terça-feira, 22 de abril de 2014

Variables and the "Defaults" mode in Blueprints

Variables are used to store values ​​of attributes of Blueprints that can be modified during the execution of the game.

To create variables, the blueprint editor must be in "Graph" mode. On the left side under the "My Blueprint" tab, there is a button to add a new variable.

When a new variable is created, its information is displayed in the "details" tab:

There are several types of variables. The image below shows the existing types in Unreal Engine 4:

For now, let's learn the simplest types of variables:
  • bool: A boolean variable can only hold the values ​​"true" or "false".
  • int: Type of variable used to store integer values​​.
  • float: Type of variable used to store fractional values​​.
  • string: This type is used to store short texts.

As an example let's create a variable that can be modified directly in the level editor of Unreal Engine 4.

Create a blueprint that contains a Static Mesh. Add an integer variable named "Resistance" and select the "Editable" option as the image below.

The "Editable" option means that the variable can be changed in the level editor.

Compile the Blueprint, then put the value 100 in "Default Value" which is on the bottom of the "Details" tab. This is the default initial value of this variable.

This value can also be modified in the "Defaults" mode of the blueprint editor that brings together the default values ​​of variables of the Blueprint.

Click to enlarge

However, note that we only added a variable and there are already several variables in the "Defaults" mode. What are these other variables?

Our blueprint inherited these variables from the Actor class. This is a basic principle of Object Oriented Programming, but this is a subject that we will only see in more detail later.

Add the blueprint created in the level. Select it and see that we can change the value of variable "Resistance" in the "Details" tab of the level editor.

Click to enlarge

Next: Class vs Objects in Blueprints
Prev: Using components in Blueprints
Table of Contents