Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 arkon · Jun 22, 2011 at 01:17 PM · instantiatedestroyhierarchy

Destroying a prefab doesn't remove it from the Hierarchy list

Hi all.

I create a prefab like this: baddie = Instantiate(Resources.Load("Alien"));

The baddie has a script and when he dies I call Destroy(gameObject) from within the alien script. This removes him from screen but doesnt remove him from the Hierarchy list which he was added to when I created him. Any ideas guys? Oh he's called Alien(Clone) in the Hierarchy.

Comment
Add comment · Show 1
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 flaviusxvii · Jun 22, 2011 at 02:47 PM 0
Share

"I create a prefab like this: baddie = Instantiate(Resources.Load("Alien"));"

Actually you're creating a GameObject, using a prefab as a template. Prefabs are abstract and never exist in the game world.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by flaviusxvii · Jun 22, 2011 at 02:48 PM

Destroy should always work. Are you sure you're not calling it on some sub-object of the Alien?

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 arkon · Jun 23, 2011 at 01:42 AM 0
Share

I call Destroy(gameObject) from within the script. Does this mean I'm only destoying the script? How do I get at the root prefab from within the script?

avatar image _Petroz · Jun 23, 2011 at 04:44 AM 0
Share

Please use the comments section or 'Edit' for follow up questions, rather than 'Answer'.

avatar image
0

Answer by _Petroz · Jun 23, 2011 at 02:22 AM

I think you're misunderstanding the difference between a Prefab and a GameObject. You can clone a GameObject using Instantiate, you can then destroy that clone from inside scripts attached to the cloned using destroy(gameObject). If you want to destroy the original object which was used to clone the new object you have to find it.

http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to destroy all gameobjects active in hierarchy? 1 Answer

GetChild(0) returns nonexistent object 1 Answer

when prefabs are spawned I want to touch them to destroy. help? 0 Answers

Destroying all enemy characters after the level is over 4 Answers

how to destroy an object then instantiate another from a prefab 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