Unreal Engine 5 Integration
During the initial phase, it's required to integrate the source code into the game and configure the necessary SARD components. You can do that by following the steps outlined below.
This tutorial focuses on how to integrate SARD using blueprints. If you prefer using pure C++, you may refer to the custom engine integration tutorial.
Preparing Blueprint Class
-
Open Your Unreal Engine Project.
-
Create a New Empty Blueprint Class to extend functionality.
-
In the "Pick Parent Class" menu, select Actor from the list of available classes.
-
Open the Blueprint to edit it.
-
Select Tools > New C++ Class in the top menu.
-
Select Actor as the parent class.
-
Name your class. In this tutorial, we name it
dllLoader
. -
As a result,
dllLoader.cpp
anddllLoader.h
files will be generated. -
Create Function Prototypes in
dllLoader.h
:
Code snippet
UCLASS()
class RUNNER_API ADllLoader : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ADllLoader();
// Called every frame
virtual void Tick(float DeltaTime) override;
void (*SardFinalizeFuncPtr)();
UFUNCTION(BlueprintCallable) bool SardInit(FString DllPath);
UFUNCTION(BlueprintCallable) void SardSetUserName(FString name);
UFUNCTION(BlueprintCallable) void SardFinalize();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
- Implement Functions in
dllLoader.cpp
for initialization, setting the username, and finalization.
Code snippet
#include "dllLoader.h"
#include <wtypes.h>
static HMODULE sard_lib;
bool ADllLoader::SardInit(FString DLLPath)
{
// Load Armour DLL
sard_lib = LoadLibraryA(TCHAR_TO_UTF8(*DLLPath));
if (sard_lib)
{
// Get SardFinalize function address
SardFinalizeFuncPtr = (void (*)())GetProcAddress(sard_lib, "sardFinalize");
// Get SardInitialize function address
void (*SardInitialize)() = (void (*)())GetProcAddress(sard_lib, "sardInitialize");
if (SardInitialize)
{
SardInitialize();
return true;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Failed to retrieve SardInitialize function address."));
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Failed to load DLL."));
}
return false;
}
void ADllLoader::SardSetUserName(FString name)
{
// Get SetUserName function in armour.dll
void (*SetUserName)(const char*) = (void (*)(const char*))GetProcAddress(sard_lib, "sardSetUserName");
// Cast FString variable to const char * type for use in SetUserName function
const char* result = StringCast<ANSICHAR>(*name).Get();
// If function pointer is valid, call function
if (SetUserName)
{
SetUserName(result);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Failed to retrieve SetUserName function address."));
}
}
void ADllLoader::SardFinalize()
{
if (SardFinalizeFuncPtr)
{
SardFinalizeFuncPtr();
}
else
{
UE_LOG(LogTemp, Warning, TEXT("SardFinalize function pointer is not valid."));
}
}
Blueprint Usage
-
Implement
SardInitialize
:- This function should be called at the start of the game.
- In
Dll Path
, provide the path toarmour.dll
. For this tutorial, use./SARD/armour.dll
.
-
Implement
SetUsername
according to the flow of your game, usually after player authorization with the game server. -
Implement
SardFinalize
at the end of the flow:- In the game exit flow.
- In the crash handling flow.
Building the Solution
- Build your project.
- Download
SardUpdater.exe
and put it in theSARD
folder in the same directory as your game.exe
. - Launch
SardUpdater.exe
with the following parameters:sardKey
: The key that can be obtained in your title at the admin panel (please refer to admin panel guide for details).sardGame
: Relative path to the game executable.- Example:
SardUpdater.exe -sardKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -sardGame "..\xxxx.exe"
SardUpdater
will download the necessary files, includingarmour.dll
(that's why theDll Path
parameter was set to./SARD/armour.dll
during blueprint setup).- Shortly after completing these steps, the functionality of the admin panel should be unlocked, confirming the success of the integration.