Sign In Register

How can we help you today?

Start a new topic
Answered

Trying to register players to GameSpark in Unity without Facebook but it's throwing a null reference .

   The code attached causes this error: NullReferenceException: No GSPlatform set for the GSInstance "default". Did you call "void Initialise(IGSPlatform platform);" ?


Trying to implement gamesparks register and auth. I can use the etst scene to aunthenticate anonymously. But not with a player registration. 


using UnityEngine;
using UnityEngine.UI;
using GameSparks.Api;
using GameSparks.Api.Requests;
using GameSparks.Api.Responses;
using GameSparks.Core;
using System.Collections;

public class RegisterPlayer : MonoBehaviour {
    public string displayNameInput, userNameInput, passwordInput; //these are set through the editor
    public bool pressed = false;

    void Awake()
    {
       
    }

    public void setPressedBool()
    {
        Debug.Log("Pressed");
        pressed = true; 
    }
                                                    
    public void registerPlayerBttn()
        {
       
        Debug.Log("RegisterPlayer");
        new RegistrationRequest()
            .SetDisplayName(displayNameInput)
            .SetUserName(userNameInput)
            .SetPassword(passwordInput)
            .Send((RegistrationResponse response) =>
          {
              string authToken = response.AuthToken;
              string displayName = response.DisplayName;
              bool? newPlayer = response.NewPlayer;
              GSData scriptData = response.ScriptData;
              var switchSummary = response.SwitchSummary;
              string userId = response.UserId;

          });

           
        }
    void Start()
    {
        registerPlayerBttn();
    }
	
} 

   


Best Answer
Did you setup GameSparks Persistent Object?
https://docs.gamesparks.net/tutorials/unity-authentication
Does the registration occur when the app starts or when you press a button etc? Looking at your script it looks like you might be doing it right when the app starts, in which case you may have to wait a frame to ensure that GS initializes first.

disregard above code, in tinkering I left some unusable syntax , please refer to this :) 

using UnityEngine;
using UnityEngine.UI;
using GameSparks.Api;
using GameSparks.Api.Requests;
using GameSparks.Api.Responses;
using GameSparks.Core;
using System.Collections;

public class RegisterPlayer : MonoBehaviour {
    public string displayNameInput, userNameInput, passwordInput; //these are set through the editor
    public bool pressed = false;

    void Awake()
    {
       
    }

    public void setPressedBool()
    {
        Debug.Log("Pressed");
        pressed = true; 
    }
                                                    
    public void registerPlayerBttn()
        {
       
        Debug.Log("RegisterPlayer");
        new RegistrationRequest()
            .SetDisplayName(displayNameInput)
            .SetUserName(userNameInput)
            .SetPassword(passwordInput)
            .Send((response) =>
          {
              string authToken = response.AuthToken;
              string displayName = response.DisplayName;
              bool? newPlayer = response.NewPlayer;
              GSData scriptData = response.ScriptData;
              var switchSummary = response.SwitchSummary;
              string userId = response.UserId;

          });

           
        }
    void Start()
    {
        registerPlayerBttn();
    }
	
}

 

Hi,


First be sure to have the GameSparks Persistent Object in your scene (check https://docs.gamesparks.net/tutorials/unity-authentication).


Then, the Start() of your script may be called before GameSparks is initialized. What you can do is use the GS.GameSparksAvailable event in  order to know when the service is available to trigger the authentication.


 

	void Start()
	{
		GS.GameSparksAvailable += (available) => {
			if (available) {
				registerPlayerBttn();
			}
		};
		//registerPlayerBttn();
	}

 

Cheers,

Vincent


1 person likes this
Answer
Did you setup GameSparks Persistent Object?
https://docs.gamesparks.net/tutorials/unity-authentication
Does the registration occur when the app starts or when you press a button etc? Looking at your script it looks like you might be doing it right when the app starts, in which case you may have to wait a frame to ensure that GS initializes first.
That was indeed it. Luckily I had a friend who knew what they were doing help me out. I was trying to contact game sparks before it had initialised and connected . Thanks for your replies that drove me crazy for a couple hours lol
Login to post a comment