- Home /
Does Unity support application bootstrapping?
I'm primarily looking for a unified solution to manage certain application level logic, e.g. dependency injection. I was hoping that there was some way that I could identify a class, or script, as code to be executed on application start up where the objects initialized would live for the life of the application (i.e. the game).
Barring that I figure I can attach initialization code to a game object on a per scene basis. I don't really like that as a solution, as I hate the idea of dependencies that need to be managed, essentially manually, for every scene. (That and I'd also like to avoid the unnecessary task of reinitializing objects on a scene-by-scene basis when the user moves from one scene to the next).
You do know about DontDestroyOnLoad, don't you? It's kind of exactly what you need here.
That's right! I forgot about that. I've been in and out of the documentation so often, but haven't used more than half of what I've read. I'll have to give that a shot. Thanks for the re$$anonymous$$der!
I usually use a seperate start scene which holds all manager objects (one one gameobject with DontDestroyOnLoad). This scene shouldn't be loaded ever again since this would duplicate the managers ;)
Therefore the start scene (level 0) immediately loads the mainmenu level. For in-editor-testing i just have a simple script in each scene which checks for the manager and if it's not there it loads the start scene. So you always have the same starting point.
I appreciate the feedback. I was thinking about the idea of a load screen while on my way into work; given what both of you are saying, it sounds like that is pretty much the accepted way of accomplishing what I'm looking to do. Thanks again!
Answer by srivello · Sep 01, 2013 at 04:19 PM
You can also run code ONCE when the SCENE loads. Amazing;
http://answers.unity3d.com/questions/45186/can-i-auto-run-a-script-when-editor-launches-or-a.html
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to initialise another 'game mode' on click? 1 Answer
Store card data 1 Answer