Unreal Engine 5 Blueprints Tutorial

In this Unreal Engine 5 Blueprints tutorial, you’ll learn how to use Blueprints to create a player character, set up inputs and make an item disappear when the player touches it. By Ricardo Santos.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 2 of 4 of this article. Click here to view the first page.

Placing the Player Start

While spawning a player, the Game Mode looks for a Player Start actor. If the Game Mode finds one, it will attempt to spawn the player there.

To place a Player Start, go to the Toolbar, click the Add New button, and navigate to Basic ▸ Player Start. Left-click and drag Player Start from the Modes panel into the Viewport. Releasing left-click will place it.

Positioning the Player Start

Place this wherever you like. When you’re done, go to the Toolbar and click Play. You’ll spawn where you placed the Player Start.

Showing the player spawned at the spawn point

To exit the game, click the Stop button in the Toolbar or press the Esc key. If you can’t see your cursor, press Shift+F1.

It’s not much of a game if you can’t move around, right? Your next task is to set up the input settings.

Setting Up Inputs

Before setting up the player inputs, it’s good to know a bit about key bindings and how to use them to create player input flexibly and powerfully.

In Unreal, you can set up key bindings that trigger an event when you press them. Events are nodes that execute when certain actions happen (in this case, when you press the bound key). When the event triggers, any nodes hooked up to the event will execute.

Showing a key binding

This method of binding keys is helpful because it means you don’t have to hard code keys.

For example, you bind left-click and name it Shoot. Any actor that can shoot can use the Shoot event to know when the player has pressed left-click. If you want to change the key, change it in the input settings.

Diagram of key bindings affecting multiple actors

If you had hard-coded it, you would have to go through each actor and change the keys individually.

Axis Value and Input Scale

In Unreal, the input is read through axis values determined in the project settings.

An axis value is a numerical value determined by the input type and how you use it. Buttons and keys output 1 when pressed. Thumbsticks output a value between -1 and 1 depending on the direction and how far you push it.

Diagram showing thumbstick values

Use the axis value to control a Pawn’s speed. For example, if you push the thumbstick to the edge, the axis value will be 1. If you push it halfway, it will be 0.5.

Adjust the speed with the thumbstick by multiplying the axis value with a speed variable.

Diagram showing the multiplication of thumbstick values

You can also use the axis value to specify a direction along an axis. If you multiply a Pawn’s speed by a positive axis value, you get a positive offset. Using a negative axis value will result in a negative offset. Adding this offset to the Pawn’s location determines its direction.

Diagram showing how axis value can affect direction

Because keyboard keys can only output an axis value of 1 or 0, you can use scale to convert it to a negative. It works by taking the axis value and multiplying it by the scale.

If you multiply a positive (the axis value) with a negative (the scale), you get a negative.

Now, on to creating the mappings for this project.

Axis and Action Mappings

To view the input settings, go to Edit ▸ Project Settings. Or click the Settings button on the top left of the editor window.

Project Settings in the editor window

On the left, select Input under the Engine section.

Input editor in the project settings

The Bindings section lets you set up your inputs.

Key binding options

Unreal provides two methods to create key bindings:

  • Action Mapping: These can only be in two states: pressed or not pressed. Action events will only trigger once you press or release the key. Use this for actions that don’t have an in-between state, such as firing a gun.
  • Axis Mapping: These output a numerical value called an axis value (more on that later). Axis events will fire every frame. You generally use this for actions requiring a thumbstick or mouse.

For this tutorial, you’ll use axis mappings.

Creating Movement Mappings

First, you’ll create two axis mapping groups. Groups allow you to bind multiple keys to one event.

To create a new axis mapping group, click the + sign to the right of Axis Mappings. Create two groups and name them MoveForward and MoveRight.

Adding action bindings

MoveForward will handle moving forward and backwards. MoveRight will handle moving left and right.

You’ll map movement to four keys: W, A, S and D. Currently, there are only two slots to map keys. Add another axis mapping to each group by clicking the + sign next to the group name field.

Create slots for keys

To map a key, click the drop-down to bring up a list of keys. Map the W and S keys to MoveForward. Map the A and D keys to MoveRight.

Result of key binding

Set the scale of the S and A keys by clicking the Scale field and entering -1.

Final result of the key binding and scale mapping

Next comes the fun part: making the Pawn move! Close the Project Settings and then open up BP_Player in the Blueprints editor by double-clicking it.

Moving the Player

First, you need to get the events for your movement mappings. In the BP_Player blueprint, click the Event Graph tab on the top of the window.

Selecting the Event Graph tab

Right-click an empty space in the Event Graph to get a list of nodes. From the menu, search for MoveForward. Add the MoveForward node listed under Axis Events.

Adding the MoveForward node

Repeat the process for MoveRight.

Movement nodes in the Event Graph

Now, you’ll set up the nodes for MoveForward.

Using Variables

To move, you need to specify how fast the Pawn is moving. An easy way to specify the speed is by storing it in a variable.

To create one, go to the My Blueprint tab and click the + sign to the right of the Variables section.

Adding variables to the Blueprint

After creating your new variable, Unreal allows you to give it a name. Set it to MaxSpeed. Afterward, in the Details tab, change the variable type to Float. Do this by clicking the drop-down next to Variable Type and selecting Float.

Change variable type to Float

Next, you need to set the default value. Before setting it, though, you must click Compile in the Toolbar to sync the default value field’s type with the newly selected Float variable type.

With your variable still selected, go back to the Details tab. Go to the Default Value section and change the default value of MaxSpeed to 10.

Setting the variable default value

Next, drag-click the MaxSpeed variable from the My Blueprint tab into the Event Graph. Select Get from the menu.

Placing the MaxSpeed variable node

You’ll now multiply MaxSpeed and the axis value to determine the final speed and direction. Add a float * float node and connect Axis Value and MaxSpeed to it.

Multiplying the variable and the input