Project

General

Profile

Randomizing characters through blueprints

What is the HowTo about?

In this HowTo we are building a blueprint to customize the player’s controlled pawn by randomly changing all the attributes of the character.

What assets are needed?

All the assets from the basic custom object HowTo.

Steps

Reaching the Customizable Object

1 - Open the Level Blueprint.


2 - In an empty area, add the following nodes. This blueprint nodes will, when the user presses the “J” key, take the player controller number 0, which in this case is the current single user, obtain the player controller’s assigned pawn, and cast it to a MutableGameCharacter type, in order to access some variables we need for our example.


3 - From this casted MutableGameCharacter, we can now access the CustomizableSkeletalComponent.


4 - A node of type Customizable Object Instance is going to be needed as well.


5 - Also, a node of type Customizable Object is needed too.


Available nodes from the Customizable Object

In this HowTo, we’re going to do all needed computations to randomly change the parameters of the player’s controlled pawn with almost all of the blueprint nodes available from the Customizable Object. A brief description of those blueprint nodes is available below.

 

Returns an integer value with the number of parameters of the Customizable Object calling this node (“Target” parameter).

 

Returns an integer value with the index of the parameter with name given by the “Name” parameter for the Customizable Object calling this node (“Target” parameter).

 
 


 

 


 

 
 

Returns an enumerated of type EmutableParameterType with the type of the parameter at index given by “Param Index” for the Customizable Object calling this node (“Target” parameter).

 

Returns a String with the name of the parameter at index given by “Param Index” for the Customizable Object calling this node (“Target” parameter).

 
 


 

 


 

 
 

Returns an integer with the number of available options the integer parameter at index given by “Param Index” has for the Customizable Object calling this node (“Target” parameter).

 

Returns a String with the name of the available option at index “K” for the parameter at index “Param Index” for the Customizable Object calling this node (“Target” parameter). This parameter at index “Param Index” needs to be a parameter of type integer parameter.

 
 


 

 


 

 
 

Returns an integer with value the available option given by the String “Value” parameter, for the integer parameter at index “Param Index”, for the Customizable Object calling this node (“Target” parameter).

 

Returns a String with value the available option given by the integer “Param Value” parameter, for the integer parameter at index “Param Index”, for the Customizable Object calling this node (“Target” parameter).

 
 


 

 


 

 

Iterating through all Customizable Object parameters

Customizable Object nodes have a list with all the parameters of a character. In this type of nodes, the Mutable character parameters are all together in one single list, so at each element of the list, the parameter present can be of type integer, float, bool, vector o projector. In the Mutable Village, integer, bool and float parameters are available (not vector nor projector), so the example will cover setting random values for integer, bool and float parameters.

7 - First, get the number of parameters available in the Customizable Object node. To obtain the number of available parameters, we can use the node “Get Parameter Count”.


8 - Now, with the integer value returned by the node “Get Parameter Count”, we’re going to iterate through all Customizable Oject node parameters. For that, we need to iterate in the range [0, “value returned by Get Parameter Count – 1”]. We build a for loop for that purpose.


9 - For each index in the loop, we want to obtain the type of the parameter at that index, so we can use a “Get Parameter type” node. The returned value is of type enumerated, so we are doing a switch on that returned value, giving us the possibility to work with each parameter according to its type.


Setting random values depending on the parameter type

10 - If the parameter is of type Bool, then it’s easy to generate a random bool value and use a node of type “Set Bool Parameter Selected Option”. This node needs as input a “Customizable Object Instance”, and the name of the parameter. Since we have the index from our loop, we can use that index value with a node of type “Get Parameter Name” to retrieve a String with the name of the parameter at that index.


11 - For the float type parameter, the approach is the same: generate a random float value (in the [0.0, 1.0] interval) and use a node of type “Set Float Parameter Selected Option”. As in the boolean case, this node needs a String with the name of the parameter to change, and a “Customizable Object Instance” as input.


12 - For the case of the integer parameter, we need to do an couple of extra steps: integer parameters have a set of available options, so we’re going to first obtain that value with a “Get Int Parameter Num Options” node, and then generate a random integer number in the interval [0, “Value returned by the Get Int Parameter Num Options node – 1”]. With that integer random value, we can obtain the name of the available option with a “Get Int Parameter Available Option” node (the “Param Index” parameter value is the index from the for loop, and the “K” parameter value is the index of the available option for that integer parameter we want to get the name). With that available option String name value, we finally use a “Set Int Parameter Selected Option” node to assign a random option for each particular integer parameter.

13 - And last but not least, we need to update the skeletal mesh of our character when the for loop ends. For that purpose we’re using an “Update Skeletal Mesh Async” node linked with the “Completed” execution of the for loop node.

Result

Play the Mutable demo in the editor and press the “J” key. You should see how the player’s controlled pawn changes all its attributes after a couple of seconds.