Storing values in variables

A variable is a programming concept. It consists of an identifier that points to a memory location where a value can be stored. For example, a character in a game may have variables to store the value of its health, its speed, and the quantity of ammunition.

A Blueprint can have many variables of various types. The variables of a Blueprint are listed on the My Blueprint panel. Clicking the + button in the Variables category creates a variable:

Blueprint is a strongly typed language. This means that you must define the type of values that a variable can store, and this type cannot be modified during program execution.

When you create a variable, its attributes are displayed in the Details panel. The first attribute of a variable is its name, and the second attribute is its type. The various types are as follows:

Each type is represented by a color. These are the types of variables:

  • Boolean: Can only hold values of true or false
  • Byte: Can store integer values between 0 and 255
  • Integer: Can store integer values
  • Float: Can store decimal values
  • Name: Can store object identifiers
  • String: Can store text
  • Text: Can store text and can support language localization
  • Vector: Contains the X, Y, and Z float values
  • Rotator: Contains the X (Roll), Y (Pitch), and Z (Yaw) float values
  • Transform: Can store location, rotation, and scale

There are also other types of variables related to Structure, Interface, Object Types, and Enum.

The following screenshot shows the Details panel with the attributes that can be modified in Variable:

These attributes can be individually described as follows:

  • Variable Name: This is the identifier of the variable.
  • Variable Type: This is the type of values that can be stored.
  • Instance Editable: When this box is checked, each copy of this Blueprint placed in the Level can store a different value in this variable. Otherwise, the same value is shared by all copies, called instances.
  • Blueprint Read Only: If checked, the variable cannot be changed by Blueprint nodes.
  • Tooltip: This contains information shown when the cursor hovers over the variable.
  • Expose on Spawn: If checked, the variable can be set when spawning the Blueprint.
  • Private: If checked, child Blueprints cannot modify it.
  • Expose to Cinematics: If checked, this variable will be exposed to Matinee/Sequencer.
  • Category: This can be used to organize the variables.
  • Slider Range: This sets the minimum and maximum values that will be used by a slider to modify this variable.
  • Value Range: This sets the minimum and maximum values allowed for this variable.
  • Replication and Replication Condition: They are used in network games.
  • Default Value: This contains the initial value of the variable. The Blueprint must be compiled before you can set the default value.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset