Packaging the game
During the development process, we extensively played the Pangaea game within Unreal Editor. However, our goal is to make the game accessible to players without requiring them to install Unreal Engine. Luckily, Unreal Engine provides a convenient packaging feature that allows us to create standalone install packages for various platforms. This means we can distribute the Pangaea game as a separate application for Windows, macOS, iOS, Android, and more. To demonstrate this, we will create a Pangaea Windows game installation package.
Prior to the packaging process for the game, certain project settings need to be configured.
Configuring the project settings for packaging
To successfully package a game, as the bare minimum, there are two tasks you need to complete, as follows:
- The first task involves setting the project defaults, which entails designating the default game mode, player pawn, and so on
- The second task involves including the necessary game levels within the generated installation package, ensuring that the game levels are present for the gameplay
Let’s start setting the project defaults in the project settings.
Setting the project defaults
To work on the settings, choose Edit | Project Settings… from the editor’s main menu. Then, from the Project Settings window, find and select Maps & Modes under the Project group on the All Settings panel. Now, choose the following settings:
- Default Game Mode:
PangaeaGameMode
- Default Pawn Class:
BP_PlayerAvatar
- Player Controller Class:
BP_TopdownPlayerController
- Game State Class:
PangaeaGameState
- Game Default Map:
LobbyMap
- Game Instance Class:
PangaeaGameInstance
We can see these settings in the following screenshot:
Figure 12.11 – Project – Maps & Modes settings
Next, we want to add the required game levels to the list of included maps.
Including the game levels in the built package
In the Project Settings window, find and select Packaging under the Project group. Then, click the Add Element button (denoted by the + symbol) to add LobbyMap
and TopDownMap
to the List of maps to include in a packaged build setting:
Figure 12.12 – Adding game maps that will be included in the package build
The project settings are now prepared for packaging the project, but if we desire the built game to run in the 1,280x720 window mode, this is the opportune moment to utilize the r.setres
console command to accomplish it.
Making the build a windowed game
By default, the packaged standalone build of the game is launched in fullscreen mode. However, it is more convenient to test the multiplayer functionality by running two instances of Pangaea in separate windows on your machine.
To facilitate this, you can configure the game to start as a windowed application with a resolution of 1,280x720 and ensure that the mouse cursor is visible. To achieve this, a minor modification can be made to the level blueprint of the LobbyMap
level blueprint, as follows:
- Execute the console command to start the game in the 1,280x720 window mode.
- Check the Show Mouse Cursor checkbox in the SET node:
Figure 12.13 – Modifying the LobbyMap level blueprint
We just accomplished the task by utilizing the LobbyMap
level blueprint to ensure we start the game with the required resolution and in window mode. One more thing to improve is to remove the hardcoded path for finding the BP_Fireball
and BP_Hammer
blueprint classes for spawning the actors.
We just completed a task that allowed us to ensure that the game starts with the required resolution and in window mode. One further improvement is to eliminate the hardcoded path used to locate the BP_Fireball
and BP_Hammer
blueprint classes for spawning actors.
Avoiding the hardcoded path for finding content
Within the game’s C++ source code, we utilized ConstructorHelpers::FObjectFinder
to obtain references to the BP_Fireball
and BP_Hammer
classes for spawning fireball and hammer instances. However, this approach employs hardcoded paths to the assets, which may lead to runtime errors when the target asset is missing or if the specified path cannot be located.
The following code snippets depict the original implementation of the ADefenseTower
and AEnemy
classes that we aim to replace.
Here is DefenseTower.cpp
:
static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/TopDown/Blueprints/BP_Fireball.BP_Fireball'")); _FireballClass = (UClass*)blueprint_finder.Object->GeneratedClass;
And here is Enemy.cpp
:
static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/TopDown/Blueprints/BP_Hammer.BP_Hammer'")); _WeaponClass = (UClass*)blueprint_finder.Object->GeneratedClass;
To improve this code, we want to define _FireballClass
and _WeaponClass
as UPROPERTY
variables so that we can select and specify Blueprint classes in the editor.
Let’s start by modifying the DefenseTower
class:
- In
Enemy.h
, change the_FireballClass
variable type toTSubClassOf<AProjectile>
. Then, move the variable definition code to thepublic
section. To maintain the code standard, we can change the variable name toFireballClass
(removing the heading underscore,_
):public: UPROPERTY(EditAnywhere, Category = "Tower Params") TSubclassOf<AProjectile> FireballClass;
- In
Enemy.cpp
, remove the following two lines of code:static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/TopDown/Blueprints/ BP_Fireball.BP_Fireball'")); FireballClass = (UClass*)blueprint_finder.Object->GeneratedClass;
- Change the parameter name from
_FireballClass
toFireballClass
when calling theSpawnOrGetFireball
function:void ADefenseTower::Fire() { auto fireball = _PangaeaGameMode->SpawnOrGetFireball( FireballClass); … }
- Select
BP_Fireball
for theFireballClass
field forBP_DefenseTower
in the editor. Then, do the following:- Compile and reopen the project in the Unreal Editor.
- Open BP_DefenseTower from the Content | Topdown | Blueprints folder.
- Select
BP_Fireball
for the Fireball Class field:
Figure 12.14 – Selecting BP_Fireball for the FireballClass field on the blueprint editor
- Compile and save
BP_DefenseTower
.
Similarly, we can apply the aforementioned steps to make modifications to the AEnemy
class. In Enemy.h
, define the WeaponClass
variable as a subclass of AWeapon
:
public: UPROPERTY(EditAnywhere) TSubclassOf<AWeapon> WeaponClass;
Then, comment or remove the two asset finder lines of code from the constructor of AEnemy
in Enemy.cpp
:
AEnemy::AEnemy() { … //static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/TopDown/Blueprints/ BP_Hammer.BP_Hammer'")); //_WeaponClass = (UClass*)blueprint_finder.Object->GeneratedClass; } void AEnemy::BeginPlay() { Super::BeginPlay(); _Weapon = Cast<AWeapon>( GetWorld()->SpawnActor(WeaponClass)); … }
We are now ready to package the game build.
Packaging the project
To package the project, we can complete the following steps:
- Click Platforms on the editor’s toolbar. Then, select Windows.
- Next, choose one of the packaging configuration types (see Figure 12.15):
- DebugGame: When packaging with this configuration, the game engine code is optimized, whereas the game code is debuggable without optimizations
- Development: This is the engine’s default compiling configuration, which only optimizes the most time-consuming engine and game code but leaves the other code unoptimized and debuggable
- Shipping: When packaging with this configuration, all debug symbols—including logs, status, profiling data, and so on—are stripped off, and the project is fully optimized for the best game performance
- Click the Package Project item on the second-layer menu.
Figure 12.15 – Starting to pack the game
- Select the target folder for where the packaged build will be saved (see Figure 12.16). Once the Select Folder button is pressed, Unreal will start the packaging process:
Figure 12.16 – Selecting the target folder (for example, C:\Projects\PangaeaBuild) to save the game build
- While packaging, you can view the progress and the logs in the Output Log window located at the bottom of the editor:
Figure 12.17 – Viewing packaging progress logs in the Output Log window
- Once the packaging process is complete, you can locate the packaged files and their corresponding subfolders in the designated target folder (see Figure 12.18):
Figure 12.18 – The generated package build files
- Then, to launch the standalone game, simply double-click on the
Pangaea.exe
executable.
Congratulations on acquiring the playable multiplayer Pangaea game build, which you can now copy and distribute to share the game with others!