Second chapter of the lecture Unreal Engine Basics taught at SAE Institute Hamburg.
- Getting familiar with the Unreal Level Editor
- Learning how to bind and handle player keyboard and mouse input
- Understanding character movement properties and functions
2. Objectives
• Getting familiar with the Unreal Level Editor
• Learning how to bind and handle player keyboard and mouse input
• Understanding character movement properties and functions
4. Unreal Levels
In Unreal, a Level is defined as a collection of Actors.
The default level contains seven of them:
• Atmospheric Fog: Provides a realistic sense of atmosphere, air density, and light
scattering.
• Floor: A simple static mesh actor.
• Light Source: Directional light that simulates light that is being emitted from a
source that is infinitely far away (e.g. the sun).
• Player Start: Location in the game world that the player can start from.
• Sky Sphere: Background used to make the level look bigger.
• SkyLight: Captures the distant parts of your level and applies that to the scene as a
light.
• SphereReflectionCapture: Captures the scene for reflection in a sphere shape.
5. Unreal Levels
Starting the game will spawn eleven more actors:
• CameraActor: Camera viewpoint that can be placed in a level.
• DefaultPawn: Simple Pawn with spherical collision and built-in flying movement.
• GameNetworkManager: Handles game-specific networking management (cheat
detection, bandwidth management, etc.).
• GameSession: Game-specific wrapper around the session interface (e.g. for
matchmaking).
• HUD: Allows rendering text, textures, rectangles and materials.
• ParticleEventManager: Allows handling spawn, collision and death of particles.
• PlayerCameraManager: Responsible for managing the camera for a particular
player.
• GameModeBase, GameStateBase, PlayerController, PlayerState
6. Asset Naming Conventions
For the same reasons we agreed on coding conventions earlier, it makes
sense to think about your project folder structure:
• Maps
• Characters
• Effects
• Environment
• Gameplay
• Sound
• UI
7. Asset Naming Conventions
For the same reasons we agreed on coding conventions earlier, it makes sense to think
about your asset names:
(Prefix_)AssetName(_Number)
with prefixes such as:
• BP_ for blueprints
• SK_ for skeletal meshes
• SM_ for static meshes
• M_ for materials
• T_ for textures
8. Blueprints
• Complete node-based gameplay scripting system
• Typed variables, functions, execution flow
• Extend C++ base classes
Thus, blueprint actors can be spawned, ticked, destroyed, etc.
• Allow for very fast iteration times
9. Hint!
By convention, maps don’t use the default underscore (_) asset naming
scheme.
Instead, they are using a combination of game mode shorthand, dash (-)
and map name, e.g.
DM-Deck
10. Putting it all together
To tell Unreal Engine which game framework classes to use, you need
to…
Specify your desired game mode in the World Settings of a map
Specify your other desired classes in your game mode (blueprint)
11. Hint!
If you don’t happen to have any assets at hand, the
AnimationStarter Pack
from the Unreal Marketplace is a great place to start.
12. Binding Input
First, we need to define the actions and axes we want to use, in the Input
Settings of our project (saved to Config/DefaultInput.ini).
13. Binding Input
Then, we need to override APlayerController::SetupInputComponent to
bind our input to C++ functions:
void AASPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
if (!IsValid(InputComponent))
{
return;
}
InputComponent->BindAxis(TEXT("MoveForward"), this, & AASPlayerController ::InputMoveForward);
}
14. Binding Input
Finally, we can apply input as character movement:
void AASPlayerController ::InputMoveForward(float AxisValue)
{
// Early out if we haven't got a valid pawn.
if (!IsValid(GetPawn()))
{
return;
}
// Scale movement by input axis value.
FVector Forward = GetPawn()->GetActorForwardVector();
// Apply input.
GetPawn()->AddMovementInput(Forward, AxisValue);
}
15. Binding Input
In order for our camera to follow our turns, we need to have it use our
control rotation:
16. Hint!
You can change the
Editor StartupMap
of your project in the project settings.
17. Binding Input Actions
Just as we‘ve been binding functions to an input axis, we can bind
functions to one-shot input actions:
void AASPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
if (!IsValid(InputComponent))
{
return;
}
// ...
InputComponent->BindAction(TEXT("Jump"), IE_Pressed, this, &AASPlayerController::InputJump);
}
18. Character Movement Properties
You can change various other properties at the
CharacterMovementComponent as well, e.g.:
• Max Walk Speed
• Jump Z Velocity (affects jump height)
19. Setting Up Logging
1. Declare your log category in your module header file:
2. Define your log category in your module .cpp file:
3. Make sure you‘ve included your module header file.
4. Log wherever you want to:
DECLARE_LOG_CATEGORY_EXTERN(LogAS, Log, All);
DEFINE_LOG_CATEGORY(LogAS);
UE_LOG(LogAS, Log, TEXT("This is some nice log output!"));
20. Unreal Log Categories
Category Summary
Fatal Always prints a error (even if logging is disabled).
Error Prints an error.
Warning Prints a warning.
Log Prints a message.
Verbose Prints a verbose message (if enabled for the given category).
VeryVerbose Prints a verbose message (if enabled for the given category).
21. Log Formatting
The UE_LOG macro supports formatting, just as in other languages and
frameworks:
FStrings require the indirection operator (*) to be applied for logging:
UE_LOG(LogAS, Log, TEXT("OnHealthChanged - OldHealth: %f, NewHealth: %f"),
OldHealth, NewHealth);
UE_LOG(LogAS, Log, TEXT("OnHealthChanged - Character: %s"), *GetName());
22. Blueprint Libraries
Unreal Engine exposes many C++ functions to blueprints, some of which
can be very useful for gameplay programming as well, e.g.:
• Kismet/GameplayStatics.h
• Kismet/KismetMathLibrary.h
(Kismet was the name of visual scripting in Unreal Engine3.)
We’ll learn how to do that ourselves in a minute.
23. Assignment #2 – Character Movement
1. Add blueprints for your code game framework classes.
2. Create a map and setup your world settings and game mode.
3. Make your character move forward, back, left and right.
4. Allow your player to look around.
5. Make your character jump.
24. References
• Epic Games. Assets Naming Convention.
https://wiki.unrealengine.com/Assets_Naming_Convention, February
2020.
• Epic Games. Introduction to Blueprints.
https://docs.unrealengine.com/en-
US/Engine/Blueprints/GettingStarted/index.html, February 2020.
• Epic Games. Basic Scripting. https://docs.unrealengine.com/en-
US/Engine/Blueprints/Scripting/index.html, February 2020.
• Epic Games. Setting Up Character Movement in Blueprints.
https://docs.unrealengine.com/en-
US/Gameplay/HowTo/CharacterMovement/Blueprints/index.html,
Feburary 2020.
25. See you next time!
https://www.slideshare.net/npruehs
https://github.com/npruehs/teaching-
unreal-engine/releases/tag/assignment02
npruehs@outlook.com
26. 5 Minute Review Session
• Where do players spawn in Unreal levels?
• How do you tell Unreal which game framework classes to use?
• Where do you define input axis mappings?
• What is the difference between axis and action mappings?
• How do you bind input?