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
0
Question by Adamant356 · Aug 21, 2012 at 06:26 PM · gameobjectinstantiatedontdestroyonloadpersistent

Instantiate from persistent GameObject

Hello,

I have recently started working on a script that is supposed to store an array of GameObjects at one scene to be instantiated at another, but the GameObjects don't persist when changing scenes. Are there any tricks available to change that? the script itself is attached to an empty GameObject with DontDestroyOnLoad enabled.

Comment
Add comment · Show 2
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 Paulo-Henrique025 · Aug 21, 2012 at 07:51 PM 0
Share

How can the script know what to instantiate if the GameObjects doesn't exist anymore, you have to persist them too.

avatar image Adamant356 · Aug 21, 2012 at 08:51 PM 0
Share

That's the question :P

Ideally I would have made a prefab out of the GameObject and stored it, but that doesn't seem to be possible. Using DontDestroyOnLoad makes a mess when objects are duplicated so I am not sure how to get around that.

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Brian Stone · Aug 21, 2012 at 08:09 PM

When you load a new scene, the scene list is cleared and all objects in the current scene are destroyed. If you don't want this to happen, then you have to explicitly set the DontDestroyOnLoad property to true for each object that you want to preserve for the next scene.

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

Edit: I guess I didn't read your question thoroughly enough. Sounds like you're already doing this.

Comment
Add comment · Show 1 · 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 Adamant356 · Aug 21, 2012 at 08:58 PM 0
Share

The GameObject the script was attached to was first started in an "initialise" scene that I wouldn't need to go back to, but these objects are in scenes that will frequently be visited by the player, leading to duplication issues that I haven't managed to solve.

If I could solve that, would it be possible to disable the GameObject until the player visits the appropriate scene, removing the need to instantiate it?

avatar image
0

Answer by Kergal · Aug 21, 2012 at 08:33 PM

mh, i am still a newbie and i am sure there is a better way, but how about something like giving each entry of the array a key store the key in f.e. the playerprefs then in the new scene if the key exists - recreate the objects (or even the whole array again).

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
avatar image
0

Answer by Kergal · Aug 21, 2012 at 08:33 PM

mh, i am still a newbie and i am sure there is a better way, but how about something like giving each entry of the array a key store the key in f.e. the playerprefs then in the new scene if the key exists - recreate the objects (or even the whole array again).

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
avatar image
0

Answer by MathieuBarbier · Aug 21, 2012 at 08:42 PM

You might put those objects under a parent that has the dontdestroy property.

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

11 People are following this question.

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

Related Questions

Problem in Instantiate Gameobject Through Network 0 Answers

Finding multiple objects by the same tag as to place them in one array? 2 Answers

MonoBehavior.Start() called infinite times? 1 Answer

Instantiated Prefab doesn't find main camera 2 Answers

Don't Destroy on Load Object and GameData 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