Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by swquinn · May 10, 2012 at 04:16 AM · c#startupinitializationdesign-patternsdependency injection

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · May 10, 2012 at 12:24 PM 0
Share

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

avatar image swquinn · May 10, 2012 at 01:14 PM 0
Share

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!

avatar image Bunny83 · May 10, 2012 at 01:25 PM 3
Share

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.

avatar image syclamoth · May 10, 2012 at 01:29 PM 0
Share

Yeah, that's what I usually do.

avatar image swquinn · May 10, 2012 at 02:14 PM 0
Share

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!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges