• 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
0
Question by mainstgrfx · Oct 15, 2011 at 10:28 PM · workflow

DontDestroyOnLoad coding procedure

Been searching here for an answer to a procedural question with no luck so here goes: Our sim's behavior relies on the users choices on a config screen. I know how to pass these via global vars using DontDestroyOnLoad(). However...When designing/creating/coding a new scene reliant on data from a previous scene, this data is not available til runtime. Other than testing every reference to the vars for their existence and accepting the processing overhead or creating dummy vars so scripts will compile and the accompanying waste of time for a lot of user choices, does anyone have some thoughts on workflow in this situation? Thanks in advance

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mike McFarland · Oct 16, 2011 at 04:37 AM

We handled a problem like this, and there probably is a better way, but I can take you through what we did. Similar to you we had a scene which took user choices and created objects used later in other scenes. We then wanted to be able to have loaded settings for each scene during dev/testing and not have to enter through the menus manually. We also wanted the to make sure the same process was used for the menus as it was for the individual scenes.

We ended up creating a spawn behaviour that on start checked to see if the scene had been entered through the menu via checking some static properties. If it hadn't been the spawn behaviour would set up static references on the menu behaviour (essentially telling it to automatically load the level with a particular set of settings). Then the spawn behaviour would load the menu scene. The menu behaviour in that scene would check these statics at start and then use that data to load the level scene set up instead of waiting for user selections. The settings used for configuration ended up being gameObjects with particular behaviours, and prefabs for this spawner were saved for common configurations. Simply add the spawner into the scene needing the data, configured properly for the scene.

After implemented I was suprised at how quickly the scene loaded for the switching, its only a split second of waiting. It was originally just a quick solution, but so far we've had no problems with it, and the workflow has been simple... so it has remained.

Comment
Add comment · Show 2 · 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
avatar image mainstgrfx · Oct 16, 2011 at 04:25 PM 0
Share

Thanks IAmCatastrophe. I was also thinking of writing user choices to a file (X$$anonymous$$L or text) and reading it in on Awake()once the new level loads to get the config. I'm sort of leaning this way as I write this since we need to record the user's history anyway, Thanks for your help.

avatar image Mike McFarland · Oct 16, 2011 at 11:11 PM 0
Share

Yea, awake would make sense, however we also were setting some references in the editor on the scripts... and starts a good time for ensuring you have the references you need

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Version control workflow 9 Answers

optimizing mesh & textures 1 Answer

Understanding how to use Perforce with Unity 1 Answer

Teamwork with different assets purchased, is it possible ? 1 Answer

multiple groups developing a single iPad game in Unity 4 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges