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 Luya · Feb 04, 2014 at 11:37 PM · colliderprefabtriggerdestroyhierarchy

Destroyed prefab still moving

Hello. I am doing the example Space Shooter from tutorials and using Unity 4.3.4f1. According to the tutorial, clones should disappear from hierarchy view but mine is still there, only the triangle on the left disappears. But I see that the Z position of the clone is increasing, so I guess the object doesn't stop. Is this expected?

I think I did everything same as tutorial. This is the code from tutorial:

 public class PlayerController : MonoBehaviour
 {
     ...
             
     void Update ()
     {
         if (Input.GetButton("Fire1") && Time.time > nextFire)
         {
             nextFire = Time.time + fireRate;
             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
 
         }
     }
 ...
 }
 
 public class DestroyByBoundary : MonoBehaviour {
 
     void OnTriggerExit (Collider other) 
     {
         Destroy(other.gameObject);
     }
     
 }
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 rutter · Feb 04, 2014 at 11:41 PM 0
Share

I'm not familiar with that tutorial, but a common mistake is to call Destroy on a component (which removes the component, but not its GameObject). Similarly, and what I might guess is happening here: if your prefab is a collection of nested/parented GameObjects, you'll need to destroy all of them (usually by destroying the parent).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AaronWinterhoff · Feb 04, 2014 at 11:52 PM

Hi. Try putting the DestroyByBoundary script on the same gameObject as the one that has the PlayerController script.

The Destroy ( other.gameObject ), function is destroying whichever gameObject your collider is on. I haven't seen the tutorial, but it's likely that this DestroyByBoundary script needs to be on the top level gameObject, so that the object deleted includes the entire hierarchy.

alt text

You will need a collider on the top level, but I'm guessing that there will be one there. It's likely this is the same object that the PlayerController script will be on.

To explain, if you have the script on a lower element, like the 'sphere' in my screen shot, it will only delete the sphere. If you have it on the SpaceShip (highlighted blue), then everything will be destroyed.

Once you have an answer you're happy with (doesn't have to be this one), please remember to upvote it and tick it as an accepted answer, to help others who might have a similar problem).


example.jpg (12.0 kB)
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 Luya · Feb 05, 2014 at 03:49 PM 0
Share

Thank you for answers! I solved it! I instantiated a shot with the tutorial's Bolt object ins$$anonymous$$d $$anonymous$$e and it worked. I compared $$anonymous$$e with tutorial's. 'shot' parameter is type of Bolt Object and Bolt has VFX object under it. Reason was, my Bolt object had Rigid Body but no Capsule Collider, while VFX had Capsule Collider without Rigid Body. I remember something like, for colliders to work, rigid body must be added.

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

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

Related Questions

How to destroy all gameobjects active in hierarchy? 1 Answer

why is OnTriggerEnter Destroy working once then stoping? 0 Answers

'Picking up Ball' by destroying Prefab, prefab does not get 'read' 1 Answer

Is there a script that will trigger a gui texture when an object is destroyed? 2 Answers

Sword Kills Enemies From Far Away 3 Answers


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