Você está na página 1de 94

AULA 1

Introdução aos Blueprints


O QUE É BLUEPRINT?
Blueprint é uma linguagem de script visual criada pela
Epic Games for Unreal Engine 4. Ele é usado dentro do
Unreal Editor para criar novas classes e
funcionalidades de jogabilidade.
Um script no Blueprint é representado por gráficos de
nós conectados por fios que definem o fluxo de
execução.
A palavra “Blueprint” também é usada para se referir a
um objeto de jogo criado usando o Blueprint.
TIPOS MAIS CONHECIDOS DE BLUEPRINTS

Level Blueprint Blueprint Class


Level Blueprint é um tipo especial de Blueprint que Blueprint Class é a definição de dados e
pertence a um Level. É usado para definir eventos e comportamento que será usada por um determinado
ações específicas em um nível (level). tipo de objeto. Uma Blueprint Class pode ser
Um level blueprint pode ser usado para interagir com baseada em uma classe C++ ou em outra classe
as classes Blueprint Actor e para gerenciar alguns Blueprint.
sistemas, como cinematics e Level streaming. Uma Blueprint Class é usada para criar objetos
interativos para o jogo e pode ser reutilizada em
qualquer nível.
When creating a new Blueprint class, you must define the parent class. All variables
OBJECT, ACTOR, AND and actions of the parent class will be part of the new class, which is known as a
ACTOR COMPONENT child class or subclass. This concept is called inheritance.
 
CLASSES Below are some parent classes:

• Object: The base class for objects in Unreal Engine. All other classes are
subclasses of the Object class.
• Actor: The base class used for objects that can be placed or spawned into a
Level.
• Actor Component: The base class for components that define reusable behavior
that can be added to Actors.

Therefore, every Actor is an Object, but not all Objects are Actors. For example, an
Actor Component is an Object, but it is not an Actor.
INSTANCES OF A
CLASS
“Instance” is a term used to reference an
object of a class.

An example can be seen in the image on


the right. Assuming there is a class called
“Blueprint_Chair” that represents a chair,
the image shows that four instances of the
Blueprint_Chair class have been added to
the Level.
CREATING BLUEPRINT CLASSES:
THE CONTENT BROWSER

To create a new Blueprint class in the Content


Browser, click the green Add New button and select
“Blueprint Class”.
CREATING BLUEPRINT CLASSES:
PICK PARENT CLASS WINDOW

The next step is to choose the parent class of the new


Blueprint.
The image on the right shows the most commonly used
classes listed in the Pick Parent Class window. Other
parent classes can be found by expanding the All
Classes option.
CREATING BLUEPRINT CLASSES:
ACTORS IN THE LEVEL

It is possible to create Blueprint classes based on


Actors that have been placed in the Level.
To do this, select the Actor in the Level and click the
blue Blueprint/Add Script button in the Level Editor’s
Details panel.
The class of the Actor will be used as the parent class
of the new Blueprint.
BLUEPRINT EDITOR INTERFACE
BLUEPRINT EDITOR:
OVERVIEW
To open the Blueprint Editor, double-click
on a Blueprint or right-click and choose
“Edit...”.
The main parts of the Blueprint Editor,
highlighted in the image to the right, are as
follows:
1. Toolbar
2. Components panel
3. My Blueprint panel
4. Details panel
5. Viewport
6. Event Graph
BLUEPRINT EDITOR:
TOOLBAR
The Toolbar, located at the top of the Editor, has a few
essential buttons for editing Blueprints:
• Compile: “Compiles” the Blueprint, necessary for
validating the code and applying modifications.
• Save: Saves all changes made to the current
Blueprint to disk.
• Browse: Shows the current Blueprint class in the
Content Browser.
• Find: Searches nodes within a Blueprint.
• Class Settings: Opens Blueprint properties.
• Class Defaults: Allows for modification of the initial
values of the Blueprint variables.
BLUEPRINT EDITOR:
COMPONENTS PANEL
In the Components panel, various types of
components can be added to the current Blueprint.
Examples of components are Static Meshes, lights,
sounds, and geometric volumes used in collision tests.
BLUEPRINT EDITOR:
MY BLUEPRINT PANEL
The My Blueprint panel is used to manage the
variables, macros, functions, and graphs of the
Blueprint.
It is separated into categories, and each category has a
“+” button for adding new elements.
BLUEPRINT EDITOR:
DETAILS PANEL
The Details panel shows the properties of the currently
selected element of the Blueprint class, which can be a
variable, function, or component.
These properties are organized into categories, and
their values can be modified.
At the top of the panel, there is a search box that can
be used to filter the properties.
BLUEPRINT EDITOR:
VIEWPORT
The Viewport contains the visual representation of the
components that are part of the Blueprint.
The components can be manipulated in the Viewport
using the transformation widgets in the same way as in
the Level Editor.
BLUEPRINT EDITOR:
EVENT GRAPH
The Event Graph is where the gameplay logic that
determines a Blueprint class’s behavior during
gameplay appears.
The Event Graph contains events and actions
represented by a node graph.
PLACING NODES
PLACING NODES:
CONTEXT MENU
The context menu is used to add nodes to the graph.
The nodes represent variables, operators, functions,
and events.
To open the context menu, right-click in an empty area
of the Event Graph or drag a wire from a pin of a node
and release the mouse button.
PLACING NODES:
PALETTE PANEL
There is a Palette panel that can be opened by going
to Window > Palette in the Blueprint Editor.
The Palette panel contains a list of all nodes that can be
used in Blueprints.
At the top of the panel there is a Favorites section that
shows the favorite and most frequently used nodes. To
set a node as a favorite, right-click on it in the Palette
panel and choose “Add to Favorites”.
PLACING NODES:
SEARCH BARS
The context menu has a search bar that filters the
nodes list when the user is typing.
The Palette panel has two search bars, one for the
Favorites section and one for the Palette list.
PLACING NODES:
CONTEXT SENSITIVE
At the top of the context menu, there is a check box
named “Context Sensitive”. If it is checked, the list of
nodes will be filtered to actions that can be used in the
current context.
If the context menu was opened by right-clicking in the
Event Graph, the context will be the current Blueprint
class. If it was opened by dragging a wire from a pin of
a node, the context will be the pin type.
NODES, PINS, AND WIRES
BLUEPRINT GRAPH
EXECUTION
The execution of the nodes of a Blueprint starts with a
red Event node and follows the white wire from left to
right until it reaches the last node. After that, it moves
on to another Blueprint event that has been triggered.
The white pins of nodes are called execution pins. The
other colored pins are the data pins.
In the image on the right, values are assigned to the
Energy and Lives variables when the BeginPlay event
is triggered.
EXECUTION PATHS
There are some nodes that control the flow of execution
of the Blueprint. These nodes determine the execution
path based on conditions.
For example, the image on the right shows a Branch
node that is using as a condition the value of the
Boolean variable Is Big Health Pack. If the value is
“true”, then the execution will continue on the True pin.
If the value is “false”, the execution will continue on the
False pin.
DATA WIRES
When a node with data pins runs, it fetches the
required data using the data wires before completing
its execution.
In the image on the right, the execution starts with the
BeginPlay event. The Set node assigns a new value to
the Energy variable, but this value must be obtained
using the data wire that is connected to a multiplication
node that will need to get the value of the Player Level
variable using another data wire.
LECTURE 2
Basic Blueprint Programming Concepts
VARIABLES
CREATING VARIABLES
Variables are used to store values and attributes in
Blueprints that can be modified during the execution of
the game. The variables can be of different types.
To create a variable, go to the My Blueprint panel in
the Blueprint Editor and click the “+” button in the
Variables category.
VARIABLE DATA TYPES
Following are common types of variables:
• Boolean: Can only hold the value “true” or “false”.
• Integer: Used to store integer values.
• Float: Used to store decimal values.
• String / Text: Used to store text. The Text variable is
preferable since it supports localization.
• Vector: Contains the float values X, Y, and Z.
• Transform: Used to store location, rotation, and
scale.
DETAILS PANEL
When a variable is selected, its properties are displayed
in the Details panel. This is where changes can be
made to the variable’s name and type.
Other properties found in the Details panel include the
following:
• Instance Editable: If checked, the variable can be
changed in the instances that are in the Level.
• Blueprint Read Only: If checked, the variable
cannot be changed by Blueprint nodes.
• Tooltip: Contains information shown when the
cursor hovers over the variable.
• Expose on Spawn: If checked, the variable can be
set when spawning the Blueprint.
ARRAY, SET, AND MAP
The Variable Type property includes a button that is
used to convert the variable into a container.
A container can store several elements of the same
type. Listed below are the types of containers available.
• Array: An ordered list of values that are accessed
using an index value.
• Set: An unordered collection of values. Duplicate
values are not allowed.
• Map: A list that uses a key-value pair to define each
entry. Duplicate key values are not allowed.
GETTERS AND SETTERS
When a variable is dragged and dropped into the Event
Graph, a context menu appears with the options Get
and Set.
Get nodes are used to read the value of the variable.
Set nodes are used to store a new value in the variable.
There are useful shortcuts to create Get and Set nodes.
To create a Get node, press the Ctrl key when dragging
and dropping a variable. The Set node is created using
the Alt key.
OPERATORS
ARITHMETIC OPERATORS
The arithmetic operators ( +, -, *, / ) can be used to
create mathematical expressions in Blueprints.
The image on the right shows a simple expression that
adds a value of “50” to the current Score variable, then
sets the newly calculated value in the Score variable.
The “+” operator receives two input values on the left
and gives the operation result on the right. To use more
than two input values, just click on the Add pin option.
The input values can be entered directly into the nodes
or can be obtained from variables.
RELATIONAL OPERATORS
Relational operators perform a comparison between
two values and return a Boolean value (“true” or “false”)
as a result of the comparison.
The image on the right shows the relational operators
and an example using a Branch node. At the end of a
game, the current player’s score (Score variable) is
compared with the highest recorded game score (High
Score variable). If the player’s score is higher, the value
of the Score variable will be stored in the High Score
variable.
LOGICAL OPERATORS
Logical operators perform an operation between
Boolean values and return a Boolean value (“true” or
“false”) as a result of the operation. The main logical
operators are as follows:
• OR: Returns a value of “true” if any of the input
values are “true”.
• AND: Returns a value of “true” only if all input values
are “true”.
• NOT: Receives only one input value, and the result
will be the reverse value.
The example on the right simulates a simple decision of
an enemy in a game. If the enemy is low on ammo (Low
Ammunition variable) and the player is nearby (Player
Is Near variable), then the enemy decides to run away.
FUNCTIONS, EVENTS, AND MACROS
FUNCTIONS
Functions allow a set of actions that are executed in
various parts of the Blueprint to be gathered in one
place for easy organization and maintenance of the
script.
Functions can be called from other Blueprints and allow
the use of input and output parameters.
To create functions, go to the My Blueprint panel in the
Blueprint Editor and click the “+” symbol in the
Functions category.
FUNCTIONS:
INPUTS AND OUTPUTS
Input parameters are values that can be passed into a
function.
Output parameters are values that can be returned
from a function.
To add input or output parameters, select the function
in the My Blueprint panel and use the Details panel.
The images on the right show a function with an input
parameter named “Value” that is added to the Score
variable.
The result of the sum is set in the Score variable, then
returned with the output parameter named “New
Score”.
FUNCTIONS:
LOCAL VARIABLES
Functions allow the use of local variables that are only
visible inside the function. They are very effective at
assisting in complex functions and do not mix with the
other variables of the Blueprint.
To create a local variable, double-click on a function to
edit it, then look at the My Blueprint panel. At the
bottom of the panel, you will find a category named
Local Variables with the name of the function in
parentheses. Click the “+” button in the Local
Variables category.
FUNCTIONS:
THE TARGET PARAMETER
The Target parameter is common to several functions
and indicates the object that will be modified with the
function call.
The default value for this parameter is “self”, which is a
special reference to the Actor or Object instance that
owns the script being executed.
The image on the right shows different ways to use the
Target parameter of the DestroyActor function.
CUSTOM EVENTS
Unreal Engine provides a number of predefined events,
but it is possible to create new ones to use in a
Blueprint. These events can be called from both the
Blueprint they are defined in and other Blueprints.
To create a custom event, right-click in the Event
Graph, expand the Add Event category, and select
“Add Custom Event...”.
CUSTOM EVENTS:
INPUT PARAMETERS
Selecting a Custom Event node allows you to manage
the event name and input parameters. Events do not
have output parameters.
The images on the right show a custom event named
“WelcomeMessage” with an input parameter called
“Name”.
The event will create and print on screen a custom
message using the name passed as a parameter.
CUSTOM EVENTS:
DELEGATES
An event has a small red square in the right corner that
is known as a delegate. This is just a reference to the
event. Some actions receive an event as a parameter,
and using the delegate makes that possible.
In the image on the right, the delegate of the custom
event named “Clock” is wired to the Set Timer by
Event node’s Event input pin, so the Clock event will
be called every second.
MACROS
Another way to gather actions in one common place is
to use macros. A macro is similar to a collapsed graph
of nodes. At compile time, the actions of a macro are
expanded in the places that the macro is being used.
Macros can have input and output parameters, as well
as several input and output execution pins.
Macros, custom events, and functions provide different ways to organize script.
MACROS Each of them has its advantages and limitations. One thing they have in common is
VS. that they all have input parameters.

EVENTS • Macros have output parameters and can have many execution paths. They
cannot be called from another Blueprint.
VS. • Events do not have output parameters. They can be called from other Blueprints
FUNCTIONS and have the “delegate” reference. They support Timelines.
• Functions can be called from other Blueprints and have output parameters.
Functions do not support latent actions, such as the Delay action.
PROGRAM FLOW
BRANCH NODE
The Branch node directs the flow of execution of a
Blueprint based on the value of the Boolean input
“Condition”, which can be “true” or “false”.
In the image on the right, there is a custom event that is
called at the end of the game. The Branch node is used
to test if the score is greater than “10000”. A different
message will be shown based on the result.
FOR LOOP NODE
The ForLoop node performs the set of actions that are
associated with the output pin Loop Body for each
index.
When the ForLoop node completes its execution, the
output pin Complete is triggered.
On the right, a ForLoop node is used to execute the
Print String node ten times. The value of the Index
output pin of the ForLoop node is used as the input for
the Print String node.
The conversion node is automatically created by the
Editor when an integer value is connected to a string
input.
SEQUENCE NODE
A Sequence node can be used to help organize other
Blueprint actions. When triggered, it executes all the
nodes connected to the output pins in sequential
order—that is, it executes all the actions of pin Then 0,
then all the actions of pin Then 1, and so on.
Output pins can be added using the Add pin + option.
To remove a pin, right-click on the pin and choose the
Remove execution pin option.
LECTURE 3
Building and Using Actor Classes
COMPONENTS
Components are ready-to-use classes that can be
used inside Blueprints. Several features can be
included in a Blueprint using only components.
To add components to a Blueprint, use the
Components panel in the Blueprint Editor.
The image on the right shows the Components panel
for a new Blueprint with some component options that
are displayed when the Add Component button is
pressed.
COMPONENTS:
VIEWPORT
The visual representation of the components can be
seen in the Viewport.
The image on the right shows the components that are
part of the ThirdPersonCharacter Blueprint from the
Third Person template. The components that have
“(Inherited)” next to the name were inherited from the
Character class.
• The CapsuleComponent is used for collision
testing.
• The Mesh component is the Skeletal Mesh that
visually represents the character.
• The FollowCamera component is the camera that
will be used to view the game.
• The CharacterMovement component contains
various properties that are used to define the
movement.
CONSTRUCTION SCRIPT
The Construction Script is a special function that all
Actor Blueprints perform when the Blueprint is first
added to the Level, when there is a change to its
properties, or when the class is spawned at runtime.
The Construction Script has a separate graph where
the actions to be performed can be placed.
It is important to note that the Construction Script
won’t run on placed Actors when the game starts.
CONSTRUCTION SCRIPT:
EXAMPLE
The Construction Script seen on the right uses the Set
Material function to define a Static Mesh component’s
Material type according to the Material selected in the
editable variable Material Type.
Whenever the Material Type variable is modified, the
Construction Script runs again, updating the object
with the new Material.
EVENTS
BEGIN PLAY EVENT
Events allow communication between Unreal Engine
and Actors. A common example is the BeginPlay
event.
The BeginPlay event is triggered when the game starts
for an Actor. If the Actor is spawned in the middle of the
game, then this event is triggered immediately.
TICK EVENT
There is an event named “Tick” that is called every
frame of the game. For example, in a game that is
running at 60 frames per second, the Tick event is
called 60 times in a second.
The Tick event has a parameter known as Delta
Seconds, which contains the amount of time that has
elapsed since the last frame.
In the Tick event illustrated on the right, an Actor moves
along the X axis at the speed of 100 centimeters per
second.
Use the Tick event only when necessary, as it can
affect performance.
COLLISION EVENTS
Collision events are triggered when two Actors collide
or overlap.
Event ActorBeginOverlap will execute when two
Actors start overlapping and the Generate Overlap
Events property of both Actors is set to “true”.
Event ActorEndOverlap will execute when two Actors
stop overlapping.
Event Hit will execute if the Simulation Generates Hit
Events property of one of the Actors in the collision is
set to “true”.
MOUSE INTERACTION
There are some events related to mouse interaction
with an Actor.
Event ActorBeginCursorOver is called when the
mouse cursor moves over the Actor.
Event ActorEndCursorOver is called when the mouse
cursor moves off the Actor.
Event ActorOnClicked is called when the mouse clicks
on the Actor.
Event ActorOnReleased is called when the mouse
button is released and the mouse cursor is still over the
Actor.
ACTOR INSTANCES
SPAWNING ACTORS
Spawn Actor from Class is a function that creates an
Actor instance using the class and transform specified.
The Collision Handling Override input defines how to
handle the collision at the time of creation. The output
parameter Return Value is a reference to the newly
created instance.
In the example on the right, when the space bar is
pressed, an instance of the Blueprint Effect Explosion
class is created at the same location (transform) of the
current Blueprint.
DESTROYING ACTORS
The DestroyActor function removes an Actor instance
from the Level at runtime. The instance to be removed
must be specified in the Target parameter.
The image on the right shows a function named “Test
Health” that will check if the value of the Health
variable is less than zero. If “true”, the current instance
of this Blueprint, which is represented by “self”, will be
destroyed.
GET ALL ACTORS OF CLASS
Get All Actors Of Class is a function that gets the
references of all the Actors in the current Level who
belong to a specified class.
The Actor Class parameter specifies the class that will
be used in the search.
The Out Actors output parameter is an array containing
references to the Actor instances of the specified class
found in the Level.
In the image on the right, Get All Actors Of Class
returns an array of BP_Coin Actors, then uses a
ForEachLoop node to set the New Hidden property to
“true” in the Set Actor Hidden In Game function for
each Actor in the array.
This can be a costly operation. Do not use it in the Tick
event.
REFERENCING ACTORS
In a Blueprint, it is possible to create a variable that
references an Object / Actor.
The example on the right shows the creation of a
variable that references an instance of the
Blueprint_Chair class. An Object Reference points to
an Actor that is in the Level.
When created, the variable is empty. A way to set an
instance to this variable is to check the Instance
Editable property, add the Blueprint to the Level, and in
the Details panel select an Actor that is in the Level.
Another way is to use the return value of the Spawn
Actor from Class function.
PLAYER INPUT
INPUT MAPPINGS
It is possible to create new input events that represent
actions that make sense in the game.
For example, instead of creating an input event for the
left mouse button that will trigger a gun, it is better to
create an action event called “Fire” and map all keys
and buttons that can trigger this event.
To access the input mappings, in the Level Editor
menu, go to Edit > Project Settings... and in the
Engine category select the Input option.
ACTION MAPPINGS
Action mappings are for key and button presses and
releases.
The image on the right shows an example of action
mappings from the First Person template.
In this example, an action named “Jump” has been
created that can be triggered by the space bar, the
bottom face button of a gamepad, or the left trigger
of a motion controller.
AXIS MAPPINGS
Axis mappings allow for inputs that have a continuous
range, such as the movement of a mouse or the analog
sticks of a gamepad.
Keys and buttons can also be used in the axis
mapping. In the example on the right, the MoveRight
action is mapped to the “D” key, with the value of the
Scale property set to “1.0”, and to the “A” key, with the
value set to “–1.0”, which represents the reverse
direction.
INPUT ACTION EVENTS
All action mappings are available in the Blueprint
Editor under Input > Action Events in the context
menu.
An InputAction event is generated when the keys or
buttons associated with it are pressed or released.
The bottom image on the right shows an example of an
InputAction event.
INPUT AXIS EVENTS
All axis mappings are available in the Blueprint Editor
under Input > Axis Events in the context menu.
An InputAxis event continuously reports the current
value of the axis.
The bottom image on the right shows an example of an
InputAxis event.
LECTURE 5
Simple Game Example
GAME CLASSES
The game created in this lecture is based on the Third
Person template. The game uses four main Blueprint
classes:
• ThirdPersonCharacter: A Pawn subclass that
represents the player and is part of the Third Person
template. This class is assigned to the Default Pawn
Class parameter of the Game Mode.
• BP_Statue: An Actor class that represents the
statue. It checks for collision with the player and has
the logic to change its position periodically.
• BP_Guide_GameMode: Controls the state of the
game and stores some variables, such as those for
time, score, and Level. It also defines the base
classes, such as ThirdPersonCharacter.
• BP_Guide_HUD: Responsible for drawing the time,
score, and Player Level values on the screen.
• The player must collect the small statues that appear on screen before time runs out.
GAME RULES
• The initial time is set at 30 seconds.
• The game is over when there is no time remaining.
• For every five statues collected, the Player Level increases and 15 seconds are added
to the time.
• The player starts at Player Level 1, and the maximum Level a player can reach is
Player Level 5.
• There are three statues in the scenario that change position periodically.
• When a statue appears in a position, it will stay there for a period of time that depends
on the current Player Level. The number of seconds it takes a statue to change
position is the result of the expression “6 – Level”.
• When the player gets a statue, another one is spawned.
• The score for a statue collected is determined by the expression “10 x Level”.
• The time, score, and Player Level values will be drawn on the screen.
CREATING THE PROJECT
Create a new project using the Third Person template
with starter content.
Remove the Static Mesh and Text Render Actors that
are in the middle of the scene, leaving only the floor
and side walls, as seen in the bottom image on the
right.
In the Content Browser, create a new folder named
“BP_Guide” that will store all new Blueprints.
BP_GUIDE_GAMEMODE

Create a new Blueprint class and choose “Game Mode


Base” as the parent class. Rename it
“BP_Guide_GameMode”.
Create the following Integer variables:
• Level: Stores the current Player Level in the game.
• Score: Stores the player’s score.
• StatueCount: Keeps track of the number of statues
collected.
• Time: Stores the time remaining until the end of the
game.
Create the following Boolean variable:
• GameOver: Indicates if the game has ended.
BP_GUIDE_GAMEMODE:
START GAME MACRO

In the My Blueprint panel, create a macro named


“StartGame”.
This macro is responsible for initializing the variables
that control the state of the game.
In the Details panel for the StartGame macro, create
an input parameter named “In” and set the type to
“Exec”. Create an output parameter named “Out” and
set the type to “Exec”.
BP_GUIDE_GAMEMODE:
START GAME MACRO
The StartGame macro will set the initial
values of the variables.
The Set Timer function creates a Timer
object that will call a custom event named
“Clock” every 1.0 seconds.
BP_GUIDE_GAMEMODE:
USING THE MACRO

The StartGame macro is called from the BeginPlay


event in the BP_Guide_GameMode Blueprint.
A custom event named “RestartGame” was created
that also calls the StartGame macro.
The RestartGame custom event is called from the
ThirdPersonCharacter Blueprint when the player
presses the Enter key, as seen in the bottom image on
the right.
BP_GUIDE_GAMEMODE:
CLOCK EVENT
Clock is a custom event that is called every second by
the Timer. It has the following responsibilities:
• To decrease by “1” the value of the Time variable
• To check if the value of the Time variable is “0”; if
“true”, to perform the following actions:
• Set the value of the Boolean GameOver
variable to “true”
• Clear the Timer so that it stops calling the
Clock event
BP_GUIDE_GAMEMODE:
STATUE COLLECTED 1/2
“Statue Collected” is a function in
BP_Guide_GameMode that is called by
the BP_Statue class when the player gets
a statue.
The first part of the function performs the
following actions:
• Adds to the value of the Score variable
the points obtained when the player
collects a statue, which is calculated
with the expression “10 x Level”.
• Adds a value of “1” to the StatueCount
variable, which stores the number of
statues collected.
BP_GUIDE_GAMEMODE:
STATUE COLLECTED 2/2
The second part of the Statue Collected
function does the following:
• Tests whether the value of the
StatueCount variable is a multiple of 5.
If “true”, it performs the following
actions:
• Adds a value of “15” to the Time
variable.
• Adds a value of “1” to the Level
variable, with the maximum value of
the Level variable limited to “5”.
This means that for every five statues
collected, the player advances a Level and
gets 15 additional seconds of time.
The modulo (%) operator returns the
remainder of the division.
BP_GUIDE_HUD

Create a new Blueprint class and choose “HUD” as the


parent class. Name it “BP_Guide_HUD”.
Create a variable named “My_Guide_GameMode” of
type “BP_Guide_GameMode Object Reference”.
The image on the right shows the BeginPlay event
getting a reference to the Game Mode, casting the
reference to BP_Guide_GameMode, and saving that
reference in the variable.
This reference will be used to access the variables that
will be drawn on the screen.
BP_GUIDE_HUD:
SCREEN COORDINATES
The only action that will be used to draw in this game is
the Draw Text function. This function receives some
input values, among them those for two parameters
known as “Screen X” and “Screen Y”, which depend
on the resolution of the screen. For example, 1280 x
720 is a common resolution.
These values represent the coordinates of the screen
on which the text will be drawn. The top left position of
the screen is the origin, where the values of Screen X
and Screen Y are “0”. The image on the right shows
how the values of these two parameters determine
where text will be drawn.
The Screen Y value used by the Score, Time, and
Level variables is “10”, so the associated text appears
at the top of the screen.
The Screen X values used are “10” by the Score
variable, “300” by the Time variable, and “550” by the
Level variable.
BP_GUIDE_HUD:
RECEIVE DRAW HUD 1/3
To draw on the screen, the Receive Draw
HUD event must be added to the Event
Graph. This event is available only in
Blueprints based on the HUD class.
The Draw Text function of the HUD class is
used to print the score on the screen, as
shown in the image on the right.
The BuildString (int) function is used to
produce a string containing the text
“Score:” plus the current value of the
Score variable. The resulting string is
passed to the Text parameter of the Draw
Text function.
BP_GUIDE_HUD:
RECEIVE DRAW HUD 2/3
The setup for drawing text for the Time and Level
variables is very similar to that for drawing text for the
Score variable.
The only changes in the Draw Text function involve the
parameters Text, Text Color, and Screen X.
BP_GUIDE_HUD:
RECEIVE DRAW HUD 3/3
The last part of the Receive Draw HUD
event tests if the value of the GameOver
variable is “true”. If it is, then it draws on
the screen the strings “GAME OVER” and
“Press Enter”.
BP_STATUE

Create a new Blueprint class and choose “Actor” as the


parent class. Rename it “BP_Statue”.
Add a Static Mesh component. In the Details panel for
the Static Mesh component, set the Static Mesh
property to “SM_Statue”.
Set the Element 0 property in the Materials category to
“M_Metal_Gold”.
Set the Collision Presets property to
“OverlapAllDynamic”.
Compile and save your Blueprint class.
Add three instances of the BP_Statue Blueprint to the
Level at any location.
BP_STATUE:
EVENT BEGIN PLAY
The image on the right shows the
BeginPlay event getting a reference to the
Game Mode, casting the reference to
BP_Guide_GameMode, and saving that
reference in the variable.
After that, the function InitStatue is called.
BP_STATUE:
FUNCTION INIT STATUE
In the InitStatue function, there are two
main nodes:
• Teleport: This node sets a new location
for the statue. The location is
represented by a vector (X, Y, Z) where
the values of the X and Y parameters
are random. The minimum and
maximum values of the X and Y
parameters represent the area of the
game.
• Set Timer by Function Name: This
Timer represents the time in seconds
that the statue will take to change
position. When this time expires, the
InitStatue function is called to set a
new position. The value of the Time
parameter is the result of the expression
“6 – Level”. “Level” is a variable from
the My_Guide_GameMode class that
represents the Player Level.
BP_STATUE:
ACTOR BEGIN OVERLAP 1/2

The ActorBeginOverlap collision event is triggered


when an Actor in the game overlaps the statue.
The value passed to the Condition input parameter of
the Branch node is the result of the expression that
checks to see if the Actor who is overlapping the statue
is the Player Character and if the GameOver variable in
the Game Mode is not set to “true”. The statue will be
collected only if these two conditions are both true.
BP_STATUE:
ACTOR BEGIN OVERLAP 2/2

If the statue is collected, the Statue Collected function


of the My_Guide_GameMode class is called to
manage the player’s score and the game Level.
After that, the current statue is destroyed and a new
one is created.
SETTING THE GAME MODE
Open the BP_Guide_GameMode Blueprint and click
the Class Defaults button. Set the Default Pawn
Class property to “ThirdPersonCharacter” and the
HUD Class property to “BP_Guide_HUD”.
In the Level Editor, click the Settings button and
choose “World Settings”. In the World Settings panel,
set the GameMode Override property to
“BP_Guide_GameMode”.
The game is now ready to play.
PLAYING THE GAME
If everything is correct, when playing the
game, the player will control a character
and must get the statues.
There are three statues in the scenario that
change position periodically.
When the player overlaps a statue, they
will receive a score and the statue will
reappear in another location.
There is a countdown, and the game is
over when there is no time remaining.
For every five statues collected, the Player
Level increases and 15 seconds are added
to the time.

Você também pode gostar