Set up zeuz in Unreal Engine

Getting Started

To use zeuz in Unreal Engine, we created the plugin, which can be downloaded for free in the Unreal Engine Marketplace .

This tutorial will guide you through you set up Unreal Engine, installation of the Zeuzsdk Marketplace Plugin and make your first API call in Unreal, using the plugin.

You can make your first API call using Blueprints, C++ or both.

Table of Contents

Unreal Setup and plugin installation

Using the SDK with Blueprint

This is an example to use the Zeuzsdk within Blueprint, it will log in into the backend which is necessary for further API calls.

  1. In the editor toolbar open BlueprintsOpen Level Blueprint
  2. Connect to the existing Event Begin Play node the ZeuzsdkAuthSimpleAuthLogin.
  3. Enter the username and password from the zeuz control panel
  4. Use the Endpoint: https://zcp.zeuz.io/api/v1
  5. Enter the Proj ID and Env ID which you want to work with from the zeuz control panel

Login Image 1

Since the API call is asynchronous the immediate output of the login node will not bear any results, instead these will be delivered by events.

  1. Create a custom event on the On Success pin and attach a Print String to show the now logged in Developer ID
  2. Create a custom event on the On Failure pin and attach a Print String to show the Error

Login Image 2

Finally start the blueprint with the play button and the result is shown in the game window.

Login Image 3

Using the SDK with C++

Calling this function from C++ is equivalent to the Blueprint version, except the output is printed to to Output instead of the screen.

  1. The Proj ID and Env ID from the zeuz control panel are saved in the default Context
  2. Username and password are entered into the authentication input struct
  3. A callback delegate is bound which will be invoked with the result of the API call
  4. The API function AuthLogin is called.
DEFINE_LOG_CATEGORY_STATIC(LogTest, Log, All);

void TestAuth() {
  FZeuzContext& ctx = FZeuzContext::Def;
  ctx.ProjID = "ovDwSBfgjlXNtBOmQqkSNlFAenS";
  ctx.EnvID = "uOJvpWmhzkVByequrudsOxcExaH";
  
  FZeuzSimpleAuthLoginIn login;
  login.Login = "demo@demo.com";
  login.Password = "demo";

  UZeuzApiSimpleAuth::FDelegateAuthLogin onresult;
  onresult.BindLambda(
    [](FZeuzContext Context, FString Error) {
      if (!Error.IsEmpty())
      {
        UE_LOG(LogTest, Warning, TEXT("Error: %s"), *Error);
      } else {
        UE_LOG(LogTest, Warning, TEXT("Success: %s"), *Context.DeveloperID);
      }
    }
  );

  UZeuzApiSimpleAuth::AuthLogin(login, onresult, ctx);
}

Using the Online Subsystem

Install the OnlineSubsystemZeuz from the marketplace or https://sdk.zeuz.io/

Add OnlineSubsystem and OnlineSubsystemZeuz to your ProjectName.Build.cs

PublicDependencyModuleNames.AddRange(new string[] { 
  "Core", "CoreUObject", "Engine", "InputCore", 
  "OnlineSubsystem", "OnlineSubsystemZeuz" 
});

Activate the OSS in your Config/DefaultEngine.ini and configure your ProjID and EnvID

[OnlineSubsystem]
DefaultPlatformService=Zeuz

[OnlineSubsystemZeuz]
Endpoint="https://zcp.zeuz.io/api/v1"
ProjID="ovDwSBfgjlXNtBOmQqkSNlFAenS"
EnvID="uOJvpWmhzkVByequrudsOxcExaH"

Now you can use the OnlineSubsystem in you project.

#include "OnlineSubsystemZeuz.h"

DEFINE_LOG_CATEGORY_STATIC(LogOSSTest, Log, All);

void IdentityLogin(FString login, FString password,FDelegateLoginBP Callback)
{
  IOnlineSubsystem* oss= IOnlineSubsystem::Get(ZEUZ_SUBSYSTEM);
  if (!oss) {
    UE_LOG(LogOSSTest, Error, TEXT("OSS not found: %s"), *ZEUZ_SUBSYSTEM.ToString());
    return;
  }
  IOnlineIdentityPtr ident=oss->GetIdentityInterface();

  FDelegateHandle delh;
  FOnLoginCompleteDelegate cb;
  cb.BindLambda(
    [Callback,&delh, ident](int32 LocalUserNum,bool Success, 
                            const FUniqueNetId& Id, const FString& Error) {
      if (!Error.IsEmpty()) {
        UE_LOG(LogOSSTest, Error, TEXT("Login Error: %s"), *Error );
      }
      else {
        UE_LOG(LogOSSTest, Log, TEXT("Login success: %i id: %s"), 
               Success, *Id.ToString());
      }
      ident->ClearOnLoginCompleteDelegate_Handle(0, delh);
      Callback.ExecuteIfBound(Success,Id.ToString(),Error);
    }
  );
  delh=ident->AddOnLoginCompleteDelegate_Handle(0, cb);

  FOnlineAccountCredentials creds;
  creds.Id = login;
  creds.Token = password;
  ident->Login(0,creds);
}

Notes and explanations