Skip to main content

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.

Note

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

  1. Open Your Unreal Engine Project.

  2. Create a New Empty Blueprint Class to extend functionality.

  3. In the "Pick Parent Class" menu, select Actor from the list of available classes.

    Pick parent class illustration

  4. Open the Blueprint to edit it.

  5. Select Tools > New C++ Class in the top menu.

  6. Select Actor as the parent class.

  7. Name your class. In this tutorial, we name it dllLoader.

  8. As a result, dllLoader.cpp and dllLoader.h files will be generated.

    Generate new C++ class illustration

  9. Create Function Prototypes in dllLoader.h:

Code snippet
dllLoader.h
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;
};
  1. Implement Functions in dllLoader.cpp for initialization, setting the username, and finalization.
Code snippet
dllLoader.cpp
#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

  1. Implement SardInitialize:

    • This function should be called at the start of the game.
    • In Dll Path, provide the path to armour.dll. For this tutorial, use ./SARD/armour.dll.

    SardInitialize in Blueprint illustration

  2. Implement SetUsername according to the flow of your game, usually after player authorization with the game server.

    SardSetUsername in Blueprint illustration

  3. Implement SardFinalize at the end of the flow:

    • In the game exit flow.
    • In the crash handling flow.

    SardFinalize in Blueprint illustration

Building the Solution

  1. Build your project.
  2. Download SardUpdater.exe and put it in the SARD folder in the same directory as your game .exe.
  3. 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"
  4. SardUpdater will download the necessary files, including armour.dll (that's why the Dll Path parameter was set to ./SARD/armour.dll during blueprint setup).
  5. Shortly after completing these steps, the functionality of the admin panel should be unlocked, confirming the success of the integration.