Trying to register players to GameSpark in Unity without Facebook but it's throwing a null reference .
P
Patrick Neary
started a topic
about 7 years ago
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
P
Paavo Kyppö
said
about 7 years ago
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();
}
}
V
Vincent Themereau
said
about 7 years ago
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.
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.
P
Patrick Neary
said
about 7 years ago
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
Patrick Neary
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.
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.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstPatrick Neary
disregard above code, in tinkering I left some unusable syntax , please refer to this :)
Vincent Themereau
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.
Cheers,
Vincent
1 person likes this
Paavo Kyppö
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.
Patrick Neary
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics