sexta-feira, 2 de maio de 2014

Actions Overview in Blueprints

We use Actions to define the behavior of a Blueprint. Actions always start from an Event. The main types of Actions are changes in the variables of the Blueprint or function calls that modify the state of Actors.

For example, imagine that the Blueprint has an integer variable called "Ammo". We want to initialize this variable with the value "50" when the game starts. To do this we use the Event "Begin Play" and drag the "Ammo" variable to the EventGraph using the "Set" option:


Each event can be added only once in the EventGraph. If we want to use more than one Action for a specific Event we have to put the Actions in sequence. The image below shows the initialization of two variables.


There are various types of functions available in the editor. To view the categories of functions, right click on the EventGraph and expand the "Call Function" option:


As an example, there is a very common function called "Destroy Actor" that removes an Actor of the game. Imagine an Item in a game that will be collected by the player. When the player is overlapping the Item, we will remove the Item from the game. To do this we can use the event "Actor Begin Overlap":


The functions allow values ​​to be passed through the use of parameters. The "Destroy Actor" function has a parameter called "Target". This parameter indicates the Actor that will be removed. The default value for this parameter is "self" which is a special reference to the Actor that owns the script being executed. In the example above, the script needs to be in the Blueprint of the Item to have it removed.

The event "Actor Begin Overlap" contains a reference to the other Actor who is colliding with the current Actor. We can use this reference as a value for the "Target" parameter of the "Destroy Actor" function:


The above script can be used in the Blueprint of the player to destroy the item that was collected.

We may also use in the "Target" parameter a variable that references an Actor. In this case, the Actor that will be removed will be the one being referenced by the variable.


This "Target" parameter is common to several functions and indicates the Actor that will be modified with the function call.