x


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).

more ▼

asked May 10 '12 at 04:16 AM

swquinn gravatar image

swquinn
73 4 5 8

You do know about DontDestroyOnLoad, don't you? It's kind of exactly what you need here.

May 10 '12 at 12:24 PM syclamoth

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 reminder!

May 10 '12 at 01:14 PM swquinn

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.

May 10 '12 at 01:25 PM Bunny83

Yeah, that's what I usually do.

May 10 '12 at 01:29 PM syclamoth

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!

May 10 '12 at 02:14 PM swquinn
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4375
x67
x39
x10
x3

asked: May 10 '12 at 04:16 AM

Seen: 590 times

Last Updated: May 10 '12 at 02:14 PM