- Home /
Game object deleted from scene but not from hierarchy?
I'm currently working on the Space Shooter tutorials, I've just completed the boundary tutorial and I'm noticing a difference between the results. In my game, the Bolt is deleted from the scene once it exits the boundary but it still shows up in the hierarchy. (I've tested this by removing my code, watching the bolt continue in the scene, and then putting my code back in to watch the bolt get deleted as it exits, so the code works and is exactly what is shown in the tutorial) Perchance is there a setting for the hierarchy that shows objects even after they have been deleted, or is my problem something much more problematic (i.e. not actually deleted)?
Answer by 13dnizinski · Jan 04, 2014 at 05:58 AM
I would venture to guess that you didn't really delete the object? It sounds a bit like you deleted the mesh from the GameObject, but the GameObject itself is still there?
This is my exact code, sadly I cant get the spacing right on this comment editor:
using UnityEngine; using System.Collections;
public class DestroyByBoundary : $$anonymous$$onoBehaviour { void OnTriggerExit(Collider other) { Destroy(other.gameObject); } }
Does the object that is being destroyed have a parent? Try destroying the top-most object:
Destroy(other.transform.root.gameObject);
That's most likely what happens here. The hierarchy is the scene. If something is shown in the hierarchy it is in the scene, even when it's not visible.
$$anonymous$$y issue is fixed, thanks guys! It turns out that the capsule collider on the bolt was in the child rather than the parent (I hadn't even remembered that there was a child at first). I've moved the collider to the correct object and everything is working flawlessly now.
Had exactly the same issue, moving collider from child object fixed for me also. Thanks for that!
Your answer
Follow this Question
Related Questions
Can't remove GameObject from scene in editor (Not appear in heirarchy, not selectable, Ghost object) 2 Answers
How to keep a GameObject inside a collider? 3 Answers
My object wont move when I use transform.translate. 2 Answers
How to add an asset to a script-enabled public game object? 1 Answer
Deleting GameObjects 1 Answer