Creating the project

Teal was the first Unreal project for most of our team. The others had worked with Unreal before, but with a much older version. The documentation for the Unreal Engine 4 can be pretty sparse, especially if you want to work with C++. So I would like to give a brief introduction into how you can get started with the Unreal Engine 4.

First you need to get the Unreal Engine (available here). You need an Epic Games account and the Epic Games Launcher is also used for the Unreal Engine. Download and launch it, then you can select one of a couple of templates to create your project. But first you have to decide whether you want to create a blueprint or C++ project.

You probably have heard that Unreal uses Blueprints and C++ for development. Blueprints are Unreal’s visual scripting language and can be used to create a full game. Blueprint only projects also allow you to compile iOS games on Windows since it uses pre-compiled blocks and therefore does not need X-Code. But you can also use C++ and that is what I will be focusing on. There are a couple more option. You select whether it is for desktop or mobile, the default quality settings and whether you want the starter content. The starter content is quite large (about 500mb) so I would add it for a prototype project and just migrate the needed files for the actual project (Unreal has its own asset migration feature and the entire process is pretty easy).

Create a blank C++ project so we can go through Unreal’s basic class structure. The viewport should be familiar to anyone that has used a 3d program. The basic camera controls are with the left mouse button and alt to rotate the camera.Alternatively you can hold down the right mouse button to move with W,A,S,D.

Get to the C++

But we want to get back to a familiar environment and in front of Visual Studio to write C++. A Unreal project is basically just the .uproject file and the content data. The Visual Studio solution can be created at any time. You can right click the .uproject file, in your file explorer and select “Generate Visual Studio project files” or use the Editor under File->“Refresh Visual Studio Project” or File->“Generate Visual Studio project files”. If you have multiple versions of Visual Studio installed, you can switch between them in the Unreal settings tab. These are under Edit->“Editor Preferences” and Edit->“Project Settings” for editor and project specific settings. Everything auto-saves in the configuration, so there is no save button.


Before we start writing code we need to understand the basic Unreal classes. The first is the GameMode or the GameModeBase. The GameMode has some additional gameplay related features that not everybody needs so they were removed in the more generic GameModeBase.

The GameMode is the main authority on how the game is played and should be used to enforce the game’s rules. It also works as the server in multiplayer games since you get the Login event for the players in the GameMode. While not necessary for single player games it is generally a good idea to use it as intended. The GameMode also only exists on the server. You will get a nullptr if you try to get the object on a client. In Teal the GameMode handles the collision detection between the units and projectiles, deals damage to the units, checks whether the match has ended and handles the turn structure. Each player sends the turn data to the GameMode and signals that the planning phase is done. Once all players are done with their planning phase the merge phase begins.


The PlayerController handles the player specific functionality. A PlayerController is spawned for every player that logs into the game. Single player games are also handled that way and the one PlayerController goes through the login process. The TealPlayerController handles all player input except the camera controls, but more on that in the pawn section. We also implemented it as a state machine because a left click has vastly different outcomes depending on the current state (unit selected, unit aiming, special tile clicked, …) and I would have gone crazy otherwise.

Pawn, Default Pawn and Spectator Pawn

A PlayerController is only one half of a player in the game and the Pawn is the other one. A Pawn is the representation of the player in the game. A pawn can be possessed by a PlayerController and then controlled. There are two pawns that are set in the GameMode. The default pawn is the pawn that is spawned with the PlayerController. This pawn is also automatically possessed by the PlayerController. The spectator pawn is spawned when a player logs in, before the match has been started by the GameMode. The class hierarchy for pawns can be a bit confusing but the main ones are:

A skeletal mesh in Unreal means a mesh with joints that can be animated. The movement component implements more advanced movement calculations and allows for fine tuned movement controls (Inertia, Acceleration, Friction).
For Teal the controlled pawn is the camera. It is actually a Pawn without a mesh and an attached camera boom.


The GameInstance is used to store any state that persists as long as the game is running. The object is created during startup and destroyed when the game is shutdown. In Teal we use it to store the lobby settings so we can read them during the match. For example whether it is a hot-seat game, the team loadouts or which replay data should be used for a replay. We also use it as common entry point for any static game data. We have a couple helper classes for various things (Key Rebindings, Map data and weapon data). The instances of these helper classes are member of the GameInstance because the GameInstance can be accessed from anywhere. This is very helpful for UI widgets.


This is mostly for completion because we do not use the GameState in Teal. The GameState is tied to the GameMode and is generally persistent for a map (Seamless Server Travel can carry over the GameMode to another map and also keeps the GameState). It is mainly used to store data that is relevant for all players in a multiplayer game. The PlayerController should hold the player specific state and the GameState the shared state. And this also has the same GameState and GameStateBase deal as the GameMode. The GameState is also automatically synchronized between all players.


This is the last of what I would consider basic Unreal classes. This is also here for completion since I myself just recently heard about it. The PlayerState holds the state for each individual player. This state is also synchronized between the players. The lifetime of the PlayerState is linked to the PlayerController. This class is not used in Teal since we did not come across it, but I would probably have used it to store the player name and color. They are now synchronized through direct RPCs, but it looks like the PlayerState would have made things much easier.

Actually get to write C++ (next time)

This is already much longer than I had anticipated. So I will leave actually writing code for next time, where we will move the table from the default scene with our trusted W,A,S,D. I hope you found this post helpful. Feel free to leave a comment if there are any further questions.

Part 2

comments powered by Disqus