Static variable issue in published

Hey guys, so I can manipulate static variables in a class that holds all my between scene information (such as which controller is controlling which unit etc.) However, this functionality only exists when play the game in development, as soon as I publish it, it seems to no longer work, as soon as I get to a line of code that tries to manipulate the static variables, I.e.:

stats.Controllers[0] = 1;

(Here I’m accessing the class which has the static variable, and adjusting it so controller[0] is searching for input from input device 1.)

The code just gets ignored for the rest of the section, if I have lines after it they are not called at all.

Does anyone have a possible solution?

I’m guessing the same way that Unity doesn’t show static vars in the Inspector, it doesn’t like to save them, either. Probably Controllers[0] is giving you a null, since Controllers wasn’t created.

Instead of static, you can make them normal public vars, and put the stats script on an empty (which Instantiates them.) You can now set them in the Inspector, they get saved the usual way, etc… . To use them: GameObject.Find("statObject").GetComponent<stats>().Controllers[0]. Or the usual where you grab a reference:

stats S; // global
S=GameObject.Find("statObject").GetComponent<stats>(); // in Start
S.Controllers[0]... // to use

Technically, Patterns people would probably call that a Singleton.