terça-feira, 14 de outubro de 2014

Switchs and Enumerations in Blueprints

Blueprint has a type of Action known as "Switch" that determines the execution flow according to the input value. The image below shows one of these actions called "Switch on Int" which takes an integer value as input.

The "Add Pin" button that is inside the "Switch on Int" Action, adds the integer output values ​​in sequence, starting at zero. You can change the initial value of the sequence in the "Details" tab of the "Switch on Int" Action:

The "Default" option of the Switch is used when the input value does not match any of the output values​​.

As an example of using the "Switch on Int" let's redo the Construction Script that was created in the previous article, using the "Switch on Int" but without changing the result of the script. The Construction Script became:

Click to enlarge

Another change that can be made to improve the Blueprint created in the previous article is to replace the integer variable "MeshType" by a variable of type Enumeration. The integer variable "MeshType" was using the values ​​1, 2 and 3, to represent the possible "Static Meshes" that would be used. These values ​​can confuse the person who is editing the level. With Enumerations we can use meaningful names.

The first step is to create a new Enumeration. In the "Content Browser" click the "New" button and in the "Blueprints" submenu select "Enumeration" as the image below.

Put the name "EMeshType" in the enumeration that was created, and double-click to edit the enumeration. Click the "New" button to add names. Write the names "Capsule", "Cone" and "Cube" as the image.

Now we need to create a new variable in the Blueprint that contains the Construction Script. The name of the variable is "MeshTypeEnum", the type is "EMeshType", which is the enumeration that was created. Check the "Editable" option and in the "Category" select or type "Construction Options":

The integer variable "MeshType" can be deleted. The options of the variable "MeshTypeEnum" in the Details tab of the Blueprint will appear like this:

Blueprint has a type of "Switch" Action based on Enumerations. This type of Switch gets the output values ​​directly from the Enumeration. The image below shows how became the new version of the Construction Script, changing the integer variable "MeshType" and "Switch on Int" by the new variable "MeshTypeEnum" and "Switch on EMeshType":

Click to enlarge

Another type of Switch that exists is the "Switch on String":

This Switch receives as input a variable of type String. The output values ​​must be added in the "Details" tab of the "Switch On String", in the "Pin Names" option:

Next: Arrays and For loops in Blueprints
Prev: Construction Script in Blueprints
Table of Contents