Per-application versus per-level editor values

Hi fellow Unity developers,

When I attach a script to a GameObject in the hierarchy, its public members become visible in the Unity editor. This is a great feature, because it means everyone can tune values when the game is actually running. And you can just drag assets to make them available in scripts.

My problem is that the hierarchy is part of a scene, i.e. the (tuned) values are specific to that level only. After finding the right value, you have to copy them to all the other levels. For some values, this is fine. You want to set them differently for each level. However, some values are essentially game-global.

So my question is: is there a simple way to get per-game (or per-application) parameters in the Unity editor? I can do it by creating an empty 'common' level with just a dummy cube with a script attached that has my game-global values in a class. When I start a normal level, I use Application.LoadLevelAdditive(), which gives me access to the values in the class (in the next frame). This works, but it seems a bit too complicated.



The solution is to make them prefabs and, when you need to change all instances, use the GameObject -> Apply Changes to Prefab menu option.

Alternately, use private vars in your scripts if they're not going to change, and / or give them a default value.

private var potatoes = 7;

This way they can't be accidentally changed in the editor. If you give a default value to a non-private var, keep in mind that any changes in the inspector will overwrite it, and if you change the default value later, it won't update the values on the existing objects.

Call DontDestroyOnLoad( this.gameObject ) method in your global script's Start() method. And it will stay forever.