Blueprint Basics (1) - Variables and Variable Types

Overview
Blueprint - is a complete visual scripting system implemented in Unreal 4. The difference between it and other scripting languages ​​(python, lua, etc.) is that it does not need to write code, and can intuitively implement the required functions by dragging and dropping nodes. But it still belongs to a programming language in essence, and it also has concepts such as variables, data types, functions, etc. It is also necessary to follow the object-oriented thinking in development, and to learn it by learning a new language, I believe it will be twice the result with half the effort.
Variable : A property that holds a value or references an Actor in the world. Any game object loaded into the game is stored by a variable of a different type.
Variable type : used to identify variables, data types include some basic variable types and reference types.
Variable Type Description
To create a variable
click the Blueprints drop-down button and click Open Level Blueprints to open the level blueprint.
Go to the MyBlueprint panel, click the '+' to the right of Variables to create a new variable, and name the variable fVal.

Go to the Details panel, click the drop-down box to the right of Variables Type, and the Variable Type dialog box will pop up

You can choose any variable type, select Float here, and click Compile to compile.
Go to the Details panel and find that under the Default Value tab, the control on the right side of Val has changed from a check box to an edit box,
enter 5 in the edit box, set the initial value of the variable, and click Compile to compile.

After creating and initializing the variable, it is time to use the variable.
Obtaining and setting
variables Click the variable fVal with the left mouse button, and drag it to the event graph, release the mouse, the menu will pop up, select Get fval to get the variable.

In the event graph, right-click, all blueprint nodes will pop up, enter Print String in the search box, click and create the node, and connect the variable's pin to the input pin of the Print String node. Due to the different types of variables, the engine Automatic variable type conversion is performed, adding a conversion node.
Now the PrintString node has no event call, so the variable cannot be output yet, and a keyboard event node needs to be added. Right-click to create the event "1" node, and then connect the execution pin, so that after pressing the "1" key, the value of fVal, which is 5, will be printed in the upper left corner of the screen. Click Compile to compile.

Click play, press the "1" key, and output the result

Variables can also be set in the program, drag the variable fVal to the event graph and click Set fVal. Create a Set node, create an event "2" node, connect to Set fVal, and click Compile to compile.

Click play to run, when the 1 key is pressed, 5 is output, when the 2 key is pressed, the variable is changed to 0, and when the 1 key is pressed again, 0 will be printed, and the result is as follows


In addition to creating variables in the above method, promoting variables can also be promoted to variables through the return value pin of the node.

Modify the variable name
to select the newly created variable, right-click the variable, click Rename, and enter the new variable name fVal01. As shown

Complex variable types
In addition to the basic variable types, some complex variable types, such as Rotator, Transform, etc., are created by organizing the basic variable types. Create a variable tVal of type Transform, set the initial value, and print the output.

Transform includes displacement (Vector), rotation (Rotator) and scaling (Scale), and outputs the result

Decomposition variables
Decompose Transform variables through the Break Transform node, and operate on the contained variable values. Similarly, the Vector variables can be decomposed through the Break Vector node.

printout.

Constructing variables
Construct Transform variables through Make Transform and assign values ​​to Transform variables. Similarly, Rotation variables can be constructed through the Make Rotation node.

printout, the Rotation in the variable tVal is reconstructed

Variable properties
Select the float type variable fVal, go to the Details panel, and view the variable properties (different variable types have slightly different properties)

Attribute Details

Attributes

illustrate

Variable Name

variable name, identifying the variable

Variable Type

Variable type, you can select other types in the drop-down box

Instance Editable

Is it editable after instantiation

Blueprint Read Only

Whether it is read-only, if it is set to read-only, the variable cannot use set

Tooltip

Prompt, prompt information for setting variables

Expose on Spawn

Is it exposed to Spawn

Private

Set whether the variable is a private variable

Expose to Cinematics

Whether exposed to Cinematics

Category

Variable classification

Slider Range

By sliding ( ) to set the variable value, the size range of the variable

Value Range

When setting the variable value by directly modifying the input box, the size range of the variable

Replication

Whether to network copy

Replication Condition

Copy method

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728503&siteId=291194637