UE Callback Handling
AndroidiOSWindows
Register the callback for the Player Network SDK; the game needs to handle the callback. It is strongly recommended to register during the application startup function.
Update Event
Add the OnUpdate call in the Unreal Engine 4 Tick event to ensure Epic's asynchronous callback 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();
}
Set the callback for the Player Network SDK UE plugin
Player Network SDK supports two methods for setting callbacks:
- Unreal Engine Event Handling Method: Register the IINTLObserver class.
- C++ Event Handling Method: Use UE C++ multicast delegate object.
| Unreal Engine Event Handling Method | C++ Event Handling Method |
|---|---|
| Usable in C++ and Blueprint (via UE event system) | Usable only in C++ |
| Unreal Header Tool (UHT) Generates Code | Unreal Header Tool (UHT) Does Not Generate Code |
| Register a Superclass | Register Multiple Different Functions Separately |
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);
// Clear callback
UINTLSDKAPI::GetAuthResultObserver().Clear();
Add Callback
Function Definition
UFUNCTION(BlueprintCallable, Category = "INTLSDKAPI")
static void AddObserver(TScriptInterface<IINTLPluginObserver> Observer);
Input Parameters
| Name | Type | Description |
|---|---|---|
| Observer | TScriptInterface<IINTLPluginObserver> | Implementation of IINTLPluginObserver instance |
Code example
TScriptInterface<IINTLPluginObserver> Observer;
Observer.SetObject(this);
Observer.SetInterface(Cast<IINTLPluginObserver>(this));
UINTLSDKAPI::AddObserver(Observer);
Remove Callback
Function Definition
UFUNCTION(BlueprintCallable, Category = "INTLSDKAPI")
static void RemoveObserver(TScriptInterface<IINTLPluginObserver> Observer);
Input Parameters
| Name | Type | Explanation |
|---|---|---|
| Observer | TScriptInterface<IINTLPluginObserver> | Implementation of IINTLPluginObserver instance |
Code Sample
UINTLSDKAPI::RemoveObserver(this);