|
My project relies on a few scripts that need to be persistent throughout the whole life of the application, and their function is to basically hold the reference and values of gameobjects and states, so I was wondering: I have just started thinking about the editor, but apart from the tutorials haven't seen much of them around: My current scripts rely on dontdestroyonload and they work with it, but I am forced to perform many .Find and .GetComponent to get the references of my scene objects and variables (there's a lot of interaction in all scenes). thanks
(comments are locked)
|
|
You can have a class (doesn't have to derive from MonoBehaviour) with public static variables. You can then just access them from everywhere in your project with ClassName.variable, but I don't think you can assign static vars in the editor. Example: Do remember though, when using statics, that they do not get reset when you load a level.
Aug 12 '11 at 08:35 AM
Kacer
Thanks a lot for the suggestion, but static offers a different approach to what I'm trying to achieve, since I'm actually trying to have these variables exposed somewhere that I don't need to instantiate or create as a gameobject in my scenes (I have a few classes that 'dontdestroy', but of course they only exist if I come from the scene they're generated into). It is perhaps possible to mix the static variable definition with an editor override or new editor class? lol my brain freezes at this point... could I possibly add a new 'project settings' submenu, like 'global objects', which could open an ad-hoc menu in the inspector? Any of you has any experience on editor tweaking to know if that's a doable solution?
Aug 12 '11 at 09:52 AM
roamcel
Singletons maybe? Thing is, you can access statics from any script, even if they arent in the scene, usually i make a script with a load of statics in them if i want to save some data between scenechanges
Aug 12 '11 at 09:57 AM
Kacer
(comments are locked)
|
thanks but this is still a bit far from what I'm asking, since to expose myPublic you need to attach the script to a gameobject in the scene.
Aug 12 '11 at 11:25 AM
roamcel
(comments are locked)
|
