Sign In Register

How can we help you today?

Start a new topic
Answered

Usage of the GameSparksUnity script

Hello all. I'm integrating GameSparks into the Unity game I'm working on. I love the platform and the online tools provided, keep up the good work :)


I have some questions regarding the use of the GameSparksUnity script that should be added to an empty GameObject in the scene: looking through the implementation I can see that it adds the DefaultPlatform component and that it automatically performs the authentication using the device ID, which is fine for testing various things in the game server. However, I'm not entirely sure what's the "official" way to adapt this solution for my final game. Do I need to write my own version of GameSparksUnity (e.g., GameSparksUnityMyGameName) and my own class that extends from PlatformBase?


I can also see that the GameSparksUnity script has the following public field:

 

public GameSparksSettings settings;

 but there are no references to this instance in the code. Is it actually needed or am I missing something?


Thanks in advance!


Best,


--Ignacio


Best Answer

Yes, there is an automatic login with the SDK after a successful authentication. We save the auth details in  player prefs so they can re-authenticate after a disconnect.

This is done in PlatformBase.cs you can see the directive GS_DONT_USE_PLAYER_PREFS is wrapped around those PlayerPrefs calls, so if you add that directive in 'scripting define symbols' in the player settings it will stop this from happening.

Alternatively you can comment out where the auth-details are stored in PlayerPrefs.

Hope that explains it :)
Sean


That settings property shows up in the Inspector where you can set it if you want (drag and drop settings file/ asset onto it). If you do not set it then GameSparks simply go look for the settings file in "Resources".

If you click on menu: GameSparks > Edit Settings you will find the asset file I am referring to.

In my own game I put the GameSparksUnity component on one of my "main" controllers. It is an object which get created early in my game and is set to DontDestroyOnLoad.

The GameSparksUnity will make a connection with GameSparks as soon as the object it is on becomes active. After that you can do whatever authentication you want to register/ login the player.

Atm I am using username/password method which might look something like this.

 

public void Login(string nm, string pw)
{
	new AuthenticationRequest()
		.SetUserName(nm)
		.SetPassword(pw)
		.Send(OnAuthenticationRequest);
}

public void Register(string nm, string pw)
{
	new RegistrationRequest()
		.SetDisplayName(nm)
		.SetUserName(nm)
		.SetPassword(pw)
		.Send(OnRegistrationRequest);
}

 

 






 

Hello Leslie,


Thank you for your reply. My main issue at the moment is that the GameSparksUnity script that ships with GameSparks (and which I'm also currently attaching to a GameObject in my initial scene) is performing not only a connection but also an authentication based on the device. I can add my own code in order to perform a username/password authentication afterwards, but I'm wondering if the fact that the GameSparksUnity script performs both a connection and an authentication on Start is correct and whether that behaviour should be expected in the final game. Can you confirm?


Thanks in advance!


--Ignacio

Did some testing and it seems like it is doing an auto login type thing.


Add this and note how the printed string is the userId of last one you logged in with on the device.


GS.GameSparksAuthenticated += (s) => Debug.LogError(":: " + s);

 


 

Indeed, yes :) Can someone from GameSparks chime in and let us know what's the recommended way to do this? Thanks in advance!


--Ignacio


1 person likes this
Answer

Yes, there is an automatic login with the SDK after a successful authentication. We save the auth details in  player prefs so they can re-authenticate after a disconnect.

This is done in PlatformBase.cs you can see the directive GS_DONT_USE_PLAYER_PREFS is wrapped around those PlayerPrefs calls, so if you add that directive in 'scripting define symbols' in the player settings it will stop this from happening.

Alternatively you can comment out where the auth-details are stored in PlayerPrefs.

Hope that explains it :)
Sean

Login to post a comment