Skip to main content

UE Observer

AndroidiOSWindows

The game must register the callback function of the Player Network SDK module to process requests.

OnUpdate

Add OnUpdate call to Unreal Engine 4 Tick event to ensure that the asynchronous callback for Epic functions properly. For more information, see UpdateSDK API.

Code sample

TScriptInterface<IINTLPluginObserver> Observer;
Observer.SetObject(this);
Observer.SetInterface(Cast<IINTLPluginObserver>(this));
UINTLSDKAPI::AddObserver(Observer);
bool UINTLSDKAPI::OnTickEvent() {
return INTLWrapper::Instance()->OnUpdate();
}

Using observers in Player Network SDK UE plugin

Player Network SDK supports 2 different ways of setting up callback:

  1. Unreal Engine event handling: Registering an IINTLObserver class.
  2. C++ event handling: Using UE c++ native Multicast Object.
Unreal Engine event handling methodc++ event handling Method
C++ and blueprints (via UE events system)C++ only
Code generated from UnrealHeaderTool (UHT)No code generated from UnrealHeaderTool (UHT)
One super class to be registeredMultiple different functions to be registered individually

Unreal Engine event handling method example

TScriptInterface<IINTLPluginObserver> Observer;
Observer.SetObject(this);
Observer.SetInterface(Cast<IINTLPluginObserver>(this));
UINTLSDKAPI::AddObserver(Observer);
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
// ...
//Handles Login callback
if(ret.MethodId == kMethodIDAuthLogin) {

}
// ...
}

C++ event handling method example

//Configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
//Remove callback
UINTLSDKAPI::GetAuthResultObserver().Clear();

Add observers

Function definition

UFUNCTION(BlueprintCallable, Category = "INTLSDKAPI")
static void AddObserver(TScriptInterface<IINTLPluginObserver> Observer);

Input parameters

NameTypeDescription
ObserverTScriptInterface<IINTLPluginObserver>IINTLPluginObserver implementation

Code sample

TScriptInterface<IINTLPluginObserver> Observer;
Observer.SetObject(this);
Observer.SetInterface(Cast<IINTLPluginObserver>(this));
UINTLSDKAPI::AddObserver(Observer);

Remove observers

Function definition

UFUNCTION(BlueprintCallable, Category = "INTLSDKAPI")
static void RemoveObserver(TScriptInterface<IINTLPluginObserver> Observer);

Input parameters

NameTypeDescription
ObserverTScriptInterface<IINTLPluginObserver>IINTLPluginObserver implementation

Code sample

UINTLSDKAPI::RemoveObserver(this);