Sign In Register

How can we help you today?

Start a new topic
Answered

Manual Connection

My game can be played as both online and offline. when i add GameSparksUnity script to my scene it tries to connect automatically. is there any way to control this script to connect when i call a function of this script? is it the only way to add remove script?



Best Answer

Here is what we do.


 

                GameSparksSettings.ApiKey = "whatever";
                GameSparksSettings.ApiSecret = "whateverwhatever";

                GameSparksSettings.DebugBuild = true;
                GameSparksSettings.PreviewBuild = true;

                GameObject g = new GameObject("GameSparksService");
                var gameSparksComponent = g.AddComponent<GameSparksUnity>();
                gameSparksComponent.settings = ScriptableObject.CreateInstance<GameSparksSettings>();

 Once that gameobject is created (next frame) - it will start connecting...


Answer

Here is what we do.


 

                GameSparksSettings.ApiKey = "whatever";
                GameSparksSettings.ApiSecret = "whateverwhatever";

                GameSparksSettings.DebugBuild = true;
                GameSparksSettings.PreviewBuild = true;

                GameObject g = new GameObject("GameSparksService");
                var gameSparksComponent = g.AddComponent<GameSparksUnity>();
                gameSparksComponent.settings = ScriptableObject.CreateInstance<GameSparksSettings>();

 Once that gameobject is created (next frame) - it will start connecting...

I override the start method in GameSparksUnity, and manually call base.Start() when I want to connect. This method is annoying because every time the API is updated, I have to re-add "protected virtual" to the start method. 


I think they should add a checkbox like "Connect on Start" to the class that we can uncheck in the inspector, and add a connect/initialize method we can call manually.


1 person likes this

I just ran into the same issue -- that would definitely be nice to have. Although 2 years old, it's the only search result that came up.

I replaced the Start() contents with public void GSInit() that I can call from a 3rd party script when ready. This seemingly HAS to be done to work with a nonce-style auth system.

Login to post a comment