• 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 · gameobjectinstantiatedestroylistreference

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

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

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

What is the best way to instatiate an array of connected GameObjects? 0 Answers

How to destroy game objects from a list 3 Answers

How to Destroy game object after a few seconds then instantiate an explosion upon death? 1 Answer

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