top of page
Writer's pictureLingheng Tao

UE4#2 Nodes Basics


Basic About Nodes


A node consists of the following 3 parts: title, inputs and outputs.

The plugs where you can plug in or drag out is called a pin.


Event nodes

Event nodes are triggered when some certain events happen. For example the node we used, the Event BeginPlay node, is executed when the game is started.


Command nodes

Command nodes executes a set of functions. There are two of them: one of them, with blue titles, is called "execution nodes"; the other, with green titles, is called "read nodes". There are two white arrows on the execution nodes, so you can decide what nodes are executed before them, and what are after. There are no white arrows on the read nodes, because they only produce values.

Sometimes the nodes will also hide some of the values. For example if you click on the down arrow on the print string node, the hidden values will be shown:

Making Annotation

Right click on the node, and you will find a list of things you can do:

At this moment let's focus on the node annotation first.

Write down something in the input field of the Node Comment, and you will be able to make your annotation to this single node.


Selecting multiple nodes and you can create a comment for the selection.






An example node connection

This is asking the screen to print a string "UE4". The node "Make Literal String" makes the things you input on the input field of Value (UE4) into a string, and the return value is passed into the node "Print String". Finally, this string is printed.


Similarly you can also do this, and it should have the same effect:

Similarly we can also "Make Literal Int". A cast node will be automatically applied here, because normally we can't pass a string as an int.


Variables


First, let's make a simple addition with nodes. Search of a "+" node, and find the "int + int" node.

You should create some node as the following:

Ok. Let's make a relatively simple connection, using the "Make Literal Int" nodes again.





Check on your UE4 about this to confirm the result. Your screen should print 3, because we have added 1 and 2.


Now, UE4 natively supports inputing a math expression. It is at the bottom of the list. Let's add something really complicated. Always remember to include parenthesis when necessary.

And you see the input values are automatically generated. It doesn't matter if you want to change the variable names:

Now that's so much of basic arithmatics.


Let's move forward to variables. In programming language we usually declare a variable like:

int a = 100;
int b;
int c,d,e;

string res = "";
bool success = false;

etc. In UE4, we also need to identify the name and the type of a variable, and they are also containers of data.

On the left side of your blueprint editor, you can see the "variables". Click on the yellow button "+ variable". (Hover your mouse next to the region)

The details will be shown on the right side of the editor. So, we can decide variable name, type, privacy, category, tooltip, etc. You may also decide the default value. Let's make a string at this moment.

Set like this, and this is almost equivalent to a declaration in the programming language as:

string message = "I am a message.";

Now you can set the value or get the value of the variable, by dragging the variable from the left panel to the editor.

Also, notice that math expressions will automatically check if you have the variables with the same names. For example:

There are no more "Tony""Steve" as input. The expression will only return by calculating these variables as inputs.







Arrays


In programming languages we sometimes declare arrays or lists, such as:

int[] numbers = new int[5];
int[] numbers;
int* numbers = malloc(sizeof(int) * 5);

In UE4 we can also create variable arrays.

By clicking on the lable on the variable type, and clicking on "array", you may make an integer array.










Compile the blueprints, and you can set the initial values of the array.

Now, you can use the "Set Array Elem" node, to set the element with the index you identified.

This is setting the 1st item value as 1. Notice that UE4 array is also 0-indexed, which means it counts from 0. When we say the first item, we actually mean the 0th item. When we say the 1st item, we refer to the second item, so on.


Similarly we can also get a value. Search for "Get Array". You may see a "get(ref)" and "get(copy)". We will talk about the difference later.

You may also add a value to the array.

Notice that this means adding 0 to the array.

You may also remove a value from the array, or even make an array with nodes. Please try on your own UE4, and see what the nodes consist of.


And these are the basic knowledge about nodes and variables.

23 views0 comments

Comments


bottom of page