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 /
This question was closed Apr 13, 2013 at 07:03 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by NeverGod · Apr 12, 2013 at 07:45 PM · gameobjectinstantiatelistdestroyreference

Destroy and rebuild game objects from lists

Hello everyone, I am trying to add checkpoints to my little game. For that reason I tried to save all objects with a given tag in my scene to a list and upon death wipe the scene of all objects and instantiate the objects I saved in the list.

making an array with GameObject's and filling it with FindObjectsWithTag does not work here since when I destroy the game object in the scene and try to instantiate it from the array, the object in the array will try to access the destroyed object in order to rebuild it.

Basically i get that my list stores only references to the objects (right?). But is there a way to store the actual objects in a variable so they can be used for instantiating later on?

Instantiating a prefab would be a workaround but considering the parameters I would have to save and reassign to each object,since all the objects are variations of a prefab, I am afraid it is by far not the best way to tackle this problem.

thanks in advance,

  • NeverGod

Comment
Add comment · Show 3
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 whydoidoit · Apr 12, 2013 at 08:02 PM 0
Share

I agree with @fafase, but if you did want to actually store them then you would need to Instantiate them into the list. Instantiate basically just copies them.

avatar image Dracorat · Apr 12, 2013 at 08:08 PM 0
Share

Both these comments combined are the right answer.

You need to clone each object with Instantiate(originalObject... and then call .SetActive(false) on the clones before you add them to the list.

avatar image NeverGod · Apr 12, 2013 at 08:47 PM 0
Share

Thanks a lot! Setting them to inactive and reactivating them worked like a charm! I wasn't aware of that little bool, I've been only using Unity since 2 days, thanks a lot!

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Apr 12, 2013 at 07:48 PM

Why don't you jsut deactivate them with SetActive? You could even have an additional boolean that says if they were actually destroyed or not.

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

Follow this Question

Answers Answers and Comments

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

Related Questions

Store Game Object Into List For Later Reinstantiation? 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Instantiating prefabs and then moving a gameobject to them 0 Answers

PlayerRespawn class wont Instantiate the player prefab 1 Answer

Instantiate an object and place it on a list. 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