So I'm trying to initialize Unity Gaming Services and am writing my own action for this. For some reason it doesn't seem to work. Any help?
This is my action:
using UnityEngine;
using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Unity Engine")]
[Tooltip("Initializes the Unity Gaming Services (UGS) and sends an event when finished.")]
public class InitializeUGS : FsmStateAction
{
[Tooltip("Event to send once the Unity Gaming Services are initialized.")]
public FsmEvent initializedEvent;
public ServicesInitializationState initializationState;
public override void Reset()
{
initializedEvent = null;
}
public override void OnEnter()
{
InitializeUGSAsync();
}
public override void OnUpdate()
{
if (initializationState == ServicesInitializationState.Initialized)
{
Debug.Log("Unity Gaming Services IS " + initializationState);
Fsm.Event(initializedEvent);
}
if (initializationState == ServicesInitializationState.Initializing)
{
Debug.Log("Unity Gaming Services is " + initializationState);
}
if (initializationState == ServicesInitializationState.Uninitialized)
{
Debug.Log("Unity Gaming Services is " + initializationState);
}
}
async void InitializeUGSAsync()
{
try
{
var options = new InitializationOptions()
.SetEnvironmentName("production");
await UnityServices.InitializeAsync(options);
}
catch (Exception exception)
{
Debug.Log("An error occured during initializing the Unity Gaming Services. Reason: " + exception);
}
}
}
}
The part on the OnUpdate method is new and I did that to check if the Service is actually initialized. Before I thought it was initialized, but for some reason at a further step that I'm doing (checking for privacy consent) it doesn't work.
Therefore all the debug part which continuously returns "Uninitialized" in the console.
Am I initializing wrong or am I checking wrong for the current state? One of both it must be...
Edit:
I also thought that the await keyword would pretty much... well... wait, until the service has been initialized. So most probably I'm checking wrong for the current state?