Sign In Register

How can we help you today?

Start a new topic
Answered

Switching between configurations

I currently have 2 configurations of my game's backend following your multi-stage publishing tutorial (One for development and one for beta testing with an eventual third configuration that will be the one that goes live when the game gets released for real soon). Since each configuration has their own API key and secret do I have to keep changing the key and secret by hand manually (I'm using Unity for my game) every time I want to switch between configurations (e.g. from my development configuration to my testing configuration) or is there an simpler way to do this?

Best Answer

I used the process below for another BaaS key/secret setup and it worked fine, unless the test button modify something it should also work on GameSparks.


- Create copies of the GameSparksSettings asset file and fill each one with the key/secret for a different environment.

- Make sure the GameObject where GameSparksUnity is attached to is a Prefab.

- Use BuildPipeline.BuildPlayer to create a custom build process where that prefab settings value is set before the build.


You can use PrefabUtility.ReplacePrefab to update the prefab value (actually replace it, which isn't scm friendly but works) and PrefabUtility.ResetToPrefabState to make sure the correct value is being used.


Hi Jason,


Each project has a unique API key, so yes, currently you will need to switch between them.


Thanks,


Oisin

Hi Oisin,

I guess it's going to be a bit of a hassle copying and pasting my keys back and forth every time I want to switch between configurations but thanks for the answer.

 

Answer

I used the process below for another BaaS key/secret setup and it worked fine, unless the test button modify something it should also work on GameSparks.


- Create copies of the GameSparksSettings asset file and fill each one with the key/secret for a different environment.

- Make sure the GameObject where GameSparksUnity is attached to is a Prefab.

- Use BuildPipeline.BuildPlayer to create a custom build process where that prefab settings value is set before the build.


You can use PrefabUtility.ReplacePrefab to update the prefab value (actually replace it, which isn't scm friendly but works) and PrefabUtility.ResetToPrefabState to make sure the correct value is being used.

 @Bruno: Any idea how I can test this in the Unity Editor? Tried making a copy of my GameSparksSettings asset file, replaced the key/secret with the one for my test environment and added it to my GameSparksUnity object but it seems to connect to my development configuration (aka my 1st/original one) by default when I test it out.

You can add the code to change the prefab in a function with a attribute to be called in a editor menu and then check if the prefab value changed.

I noticed this was posted a year ago -- is there an easier way to change settings? I copied the settings prefab twice, but what is the best practice to apply this? Anyone have sample code, by chance (I'm horrible with editor scripting)?

(Is there a way to just swap the keys at runtime? GS.secret = "this" / GS.apiKey = "that"?

@Dylan: You can use GameSparksSettings.ApiKey/ApiSecret for something like that.


Anyway what I did was a bit hackish (and maybe not ideal) but I created a singleton manager script containing all my keys along with an enum you can use to switch between configurations (e.g. Developing, Testing, Production etc.) then at runtime you can check which configuration is active and change the key/secret to the appropriate one.

Login to post a comment