Base Classes

Firstly we should implement our game mode class and corresponding classes we are going to be setting in our game mode. We are not going to use any of the default classes, so we need to create each one of them separately.

Before starting, if any of the following code chunks do not contain a class implementation then that class is just an empty class, but you should pay attention to make the classes derived from base or Unreal’s default derived classes(e.g.: GameMode and GameState or GameModeBase and GameStateBase etc.).

Let’s start with our game mode:

Game Mode

Game mode class is the heart of our games in Unreal Engine. It controls a lot of things like our HUD, PlayerController, main player pawn and so on, then it spawns an instance of all of these classes at the beginning of the game. For example, a spectator pawn class will be spawned and the camera component it has will be set as the main camera.

Player Controller

Player controller class is the brain of the player pawn. It gets input from the player and tells pawn what to do. Basicly it provides the communication between pawn and the player. Actually we can make all of our input controls in our spectator pawn class, but we want to be away from complexity.

Input Settings

Spectator Pawn

Spectator pawn will be the main pawn class, and players will control this class and its children. We are going to start implementing this class by adding input controls and a camera component. Later on we are going to move the input operations to player controller.

Camera Component

Camera component is the eye of a player. In camera component class, we are going to set movement and zooming functions, camera rotation, and move the camera according to the mouse position. Even if the movement parameters come from the spectator pawn, we are setting owning pawn’s location here because of the mouse operations.

Final demo:

Github link: https://github.com/emrebarisc/RTSBattleRoyale

By the way, you should check output log frequently for warnings and errors if you think your code should be working but it does not. Output log gives quite good information in such cases.

Next time I am going to go over our character implementation. Until then, take care 🙂

P.s. I cannot take all the credits for this article because I’ve taken some help from Unreal Engine’s strategy game tutorial.  This tutorial is a huge source of knowledge for me and I recommend you to check it out as well.