Set up the Unreal SDK #
This tutorial involves setting up and integrating the Pragma Unreal SDK. This includes generating the Pragma SDK sources, integrating it into an Unreal project, initializing it, and logging in to the Pragma backend with a test user.
Unreal example project #
This tutorial is based on an example Unreal project using the Third Person Unreal C++ project template. The example project is named ‘Unicorn’, update references accordingly.
This tutorial was built and tested using Unreal 5.3.X, see the SDK overview for the full sdk compatibility chart.
SDK code generation config #
In your pragma project config file, ensure the sdk type is set to Unreal:
pragma-engine\platform\pragma-cli.ini
sdk = unreal
Set the PRAGMA_SDK_UNREAL_PROJECT_ROOT environment variable to the absolute path of your Unreal project (e.g. in your .bashrc / .zshrc). pragma sdk update appends Plugins\PragmaSDK to it automatically:
export PRAGMA_SDK_UNREAL_PROJECT_ROOT="~/[game_repo_root_dir]/Unicorn"
Set up the Pragma SDK Plugin #
- Stop pragma engine if it’s running locally.
- From
pragma-engine\platform, run./pragma sdk generate-and-updatein git bash. - Confirm the
PragmaSDKfolder and sources now exist in your UnrealPluginsdirectory.
Configure the Pragma SDK #
- In Unreal, add
PragmaSDKandPragmaSDKAuxto thePublicDependencyModuleNamesarray:
Source\Unicorn\Unicorn.Build.cs
PublicDependencyModuleNames.AddRange(
new string[] {
// ...
, "PragmaSDK", "PragmaSDKAux"
}
);
- Add the following configuration properties.
Config\DefaultGame.ini
[/Script/PragmaSDK.PragmaSdkConfig]
BackendAddress="http://127.0.0.1:10000"
GameClientVersion="DefaultGameClientVersion"
Enabling verbose logging will log all backend API calls which is helpful during integration. This can be reduced / disabled later to reduce noise.
Config\DefaultEngine.ini
[Core.Log]
LogPragma=VeryVerbose
- Build your Unreal project now that the PragmaSDK plugin is included.
Initialize the Pragma LocalPlayerSubsystem #
Pragma provides a LocalPlayerSubsystem that initializes the Pragma SDK and establishes a connection to the backend.
This code can be placed wherever it makes sense based on how the game is initialized, this example uses a PlayerController and GameModeBase.
Set up the Player Controller #
- If one doesn’t already exist, create a PlayerController class (eg.
UnicornPlayerController) - Add the following code:
Source\Unicorn\UnicornPlayerController.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PragmaPtr.h"
#include "UnicornPlayerController.generated.h"
PRAGMA_FWD(FPlayer);
UCLASS()
class UNICORN_API AUnicornPlayerController : public APlayerController
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
UFUNCTION(Exec)
void LogIn(const FString& Username);
UFUNCTION(Exec)
void LogOut();
private:
Pragma::FPlayerPtr Player;
};
Source\Unicorn\UnicornPlayerController.cpp
#include "UnicornPlayerController.h"
#include "PragmaPlayer.h"
#include "PragmaLocalPlayerSubsystem.h"
void AUnicornPlayerController::BeginPlay()
{
Super::BeginPlay();
const auto* Pragma = GetLocalPlayer()->GetSubsystem<UPragmaLocalPlayerSubsystem>();
Player = Pragma->Player();
// Log in using a built-in test account.
// Accounts test01 - test20 are available by default.
LogIn("test01");
}
void AUnicornPlayerController::LogIn(const FString& Username)
{
Player->LogIn(
EPragma_Account_IdProvider::UNSAFE,
Username,
Pragma::FPlayer::FLoggedInDelegate::CreateWeakLambda(
this, [this, Username = Username](const TPragmaResult<>& Result)
{
if (Result.IsSuccessful())
{
UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged in as user %s."),
*Username);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Pragma -- Login failed: %s"),
*Result.GetErrorAsString());
}
}));
}
void AUnicornPlayerController::LogOut()
{
Player->LogOut(
Pragma::FPlayer::FLoggedOutDelegate::CreateWeakLambda(
this, []
{
UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged out."));
}));
}
- If not already completed, register the PlayerController with your GameMode
Source\Unicorn\UnicornGameMode.cpp
#include "UnicornPlayerController.h"
// ...
AUnicornGameMode::AUnicornGameMode()
{
// ...
PlayerControllerClass = AUnicornPlayerController::StaticClass();
}
Run the game #
- Ensure Pragma is running via
./pragma runor the Intellijrun-pragmarun configuration. - Run the game
- Confirm the login was successful via the log:
Pragma -- Logged in as user test01. - Success!
Recap #
We’ve generated the Pragma SDK, initialized the LocalPlayerSubsystem and logged in using a test account. Move this functionality to its proper lifecycle location within the game flow as needed and build out from there.
Next we’ll demonstrate how to initialize and call Pragma services.