Sign In Register

How can we help you today?

Start a new topic

How to get GameSparks.Core.GS.Authenticated info on Start() method?

hi,


I have a login screen and I want to check inside the Start() method if the user is already authenticated.


I found that GameSparks.Core.GS.Authenticated will work, but not inside the Start() method. It seems only after some time has passed, like a button is pushed somewhere in the UI, only then will GameSparks.Core.GS.Authenticated be populated.


What is the trigger point to get GameSparks.Core.GS.Authenticated and the GSInstance class to be populated?

Is this happening because GameSparks is still initializing during the Start() method? Is there some way to hook into an event that fires after GS initializes?




1 person has this question
1 Comment

Hi Drew,


Yes you are correct that it takes a small amount of time for the Unity SDK and Gamesparks to connect. This will result in GS.Authenticated being false when the game is initialized as Gamesparks hasn't connected yet if its in the start method. To overcome this you can use the GS.Instance.GameSparksAuthenticated callback and subscribe a custom event to it. Inside the custom event you can have you have what kind of logic you want when the player automatically logs in. For example close the login menu or load a new scene etc.

Just a note on Authentication in Unity when you authenticate with Unity it saves the auth tokens to the playerprefs locally I would advise deleting any auth tokens in order to test this with new players. This is because if an authentication request is not called the Unity SDK will perform one in the background automatically authenticating the user and using the stored authentication token that was stored in playerprefs. If this is just a test project you can call PlayerPrefs.DeleteAll() this will delete all playerPrefs including all auth tokens and any other data saved in playerPrefs. If you don't want to do this you can reset the authTokens using resetAuthTokens via cloud code.


I hope this helps you out if you have any further questions don't hesitate to contact us.


Regards,

Garreth.


2 people like this
Login to post a comment