segunda-feira, 22 de dezembro de 2014

Flow Control in Blueprints

There are some Actions that are used to control the flow of execution of the others actions in a Blueprint. We have seen some of these Actions:
  • Branch: Determines the flow based on a condition;
  • For Loop: Repeats a set of actions for a certain number of times.
  • Switch: Determines the flow based on the value of the input variable.
  • Flip Flop: Toggles between two execution outputs.

There are other flow control actions. Let's start analyzing the "Sequence":

The "Sequence" can be used to help organize the Blueprints Actions. When activated, it performed in order all the actions linked to the output pins.

The Action "Do Once" performs only once the actions linked to the output pin. As an example let's modify the script created in the article "Using Level Blueprints"In this example we have a trigger that generates an explosion when the player collides with it. The trigger was destroyed so that the explosion was generated only once. Using the action "Do Once" is not necessary to destroy the trigger for the explosion to happen only once. The modified script became:

Click to enlarge

Even if the player generates new collision events with the trigger, the action "Do Once" will not let pass the execution flow. The input pin "Reset" can be used so that "Do Once" can perform the output actions again.

The action "Do N" is similar to action "Do Once", but we can enter the number of times the output actions can be performed. In the example below, the player has 3 Medical Kits which is used when the "M" key is pressed. After pressing 3 times the "M" key, the action that restores the variable "health" will no longer be performed. To reload the medical kits, the player must collide with an actor of the type "BP_MedKitStore" which is responsible for restoring the medical kits of the player. It does this using the "Reset" input pin of the "Do N" action.

Click to enlarge

The "Gate" action can be open or closed. If it is open it allows the execution of the actions related to the output pin. The input pins "Open", "Close" and "Toggle" are used to define the current state of "Gate". There is also the boolean variable "Start Closed" that determined if the "Gate" should start running in the "Closed" state.

In the example below we have an Actor called "HealthGenerator". When the player is colliding with this actor, his health will be restored slowly every "Tick" event. If the player stops colliding with the "HealthGenerator", the "Gate" will be closed and the actions that restore health are no longer performed. The action "Min" is used so that the value of the variable "Health" is never greater than 100.

Click to enlarge

The action "Multigate" can be used in various ways. Can be added multiple output pins and each time the "Multigate" triggers only one of these output pins in order or randomly. The number of output pins determines the number of times that the "Multigate" will perform. However, there is the "Loop" variable that indicates whether the "Multigate" should continue to run the output pins.

In the example below we use a "Multigate" with random outputs and in loop. When the player collides with an actor of type "RandomBonus" he will benefit from a random bonus that can be Health, Gold or Ammo. To keep the code simple, the action that represents a bonus only displays a message on screen.

Click to enlarge

Next: Input Mappings in Blueprints
Prev: Using Timelines in Blueprints
Table of Contents