segunda-feira, 3 de novembro de 2014

Using Level Blueprints

The Blueprints that we created so far are known as "Class Blueprints". Unreal Engine 4 has a special type of Blueprint called "Level Blueprints". Each level of the game has a default Level Blueprint. To access the Level Blueprint click the "Blueprint" button at the top of the editor and choose the "Open Level Blueprint" option:


The "Level Blueprint" opens in the "Graph" mode which is practically the same as in a "Class Blueprint". You can do many things in the Level Blueprint, but it is important to stay in the Level Blueprints only Actions that are specific to the current Level. Actions related to an Actor that can be reused in many other levels must be converted into a "Class Blueprint".

There are some types of Actors that are widely used together with Level Blueprints. The type of these Actors are "Trigger" and "Target Point". These Actors are available in the editor in the "Basic" category of the "Place Mode":


As an example, imagine that a level has two areas linked by a bridge, and that the only way to access the second area is across this bridge. This bridge is a great place to put a Trigger that will generate an event when the player passes through it.

This event can create new enemies in the second area or generate an explosion. The image below illustrates this idea showing a "Trigger Box" that was placed on the bridge. The "Trigger Box" is not displayed during the game.

Click to enlarge

We use the "Target Point" to easily create reference points on the Level. Following the example above add an "Target Point" on the level to indicate where the explosion will be generated when the player touches the "Trigger Box". Put the name of the "Target Point" as "ExplosionPlace":


The scale values ​​of the Target Point are in 5.0 because they are used to increase the size of the explosion. The end result of this "Level Blueprint" will look like the image below, where the player detonates an explosion when passing through the Trigger:


To create the actions of the Level Blueprint responsible for the explosion, first select the "Trigger Box" that was added to the Level. Then open the Level Blueprint and right click to open the Actions menu. The "Context Sensitive" option must be checked.

At the beginning of the list will appear the actions related to the "Trigger Box" that is selected in the level, as the image below. You need to add the "OnActorBeginOverlap" event and you must also choose "Add Reference to TriggerBox" to create a variable that represents the Trigger Box in the "Event Graph".


We will also need a reference to the "Target Point" where the explosion should occur. To do this, go back to the level and select the "Target Point" which we named "ExplosionPlace", then return to the Level Blueprint, right click on the Event Graph and choose the option "Add Reference to ExplosionPlace":


We already have the main elements that will be in the Event Graph. When the event is triggered, the "Trigger Box" will be destroyed, because we want this event to occur only once, then we create a new Actor based on "Blueprint_Effect_Explosion" that is part of "Start Content" of the editor. This new actor is created at the position where is the "Target Point" named "ExplosionPlace". The Graph of the Level Blueprint will be as follows:

Click to enlarge

To create the explosion we use the "SpawnActor" action and in the Class parameter we select "Blueprint_Effect_Explosion_C" class that is equivalent to "Blueprint_Effect_Explosion". The other parameter used is the "Spawn Transform" which is obtained from the "Explosion place". A "Transform" contains information about the location, rotation and scale of an Actor.

In the next article we will learn about "Event Dispatchers" which allow a kind of interaction between "Class Blueprints" and "Level Blueprints".