sexta-feira, 25 de abril de 2014

Class vs Objects in Blueprints

The words "class" and "objects" can confuse those who are starting in Blueprints. When we create a new blueprint, we are creating a class, which is a kind of template that defines the features and behavior of objects that are created from this class.

For example, in previous articles I created a class called "HelloUnreal" containing a "Static Mesh". The image below shows 4 objects of this class that have been added to the level.


These objects are also known as instances of the "HelloUnreal" class. The word "instance" is very common in the Unreal Engine 4 editor, so it is important to get used to it.

The Actors are objects that can be added to the level.

Each object has its own set of variables based on the origin class but with independent values ​​in relation to other objects. Imagine a class of type "Person", we would be objects of this class with different names, ages and weights. 

In a blueprint we can create a variable that references other objects, the image below shows the top of the list of objects available in the selection of the variable type:


We can also create variables that reference the classes:


The most common is the creation of variables referencing objects. The variables that reference classes are used only in some very specific cases.

As an example, let's create a new blueprint with a variable that references another object blueprint, which in this case will be the HelloUnreal blueprint. This will allow communication between the blueprints and is very useful in the creation of a game.

Create a new blueprint with the name "ObjRef" (or any other name of your choice). Create a new variable named "HelloObj", select the "Editable" option and in the variable type select the "HelloUnreal_C" class blueprint which is in the "object" category.


The name of the classes created by blueprint has the suffix "_C" which is automatically inserted by the editor.
( Note: After the 4.5 version of the editor, this "_C" suffix is no longer used, so the class name and the blueprint name became equal )

Add this new blueprint in the level. The image below shows the "Details" tab containing the "HelloObj" variable.


Click the ComboBox that is beside the variable name "HelloObj". The editor will list the actors that are at the level that belong to HelloUnreal class. Choose one from the list.


In the "Graph" Mode of the "ObjRef" blueprint we can drag the "HelloObj" variable to the "EventGraph" using the "Get" option. This way we can access the variables and functions of the blueprint that is being referenced by the variable.

Click to enlarge