I made a 2D edge collider which on contact destroys the other gameobject. When I launch the game all the other gameobjects in fact get destroyed but the clones are still listed in the Hierarchy. How can I get rid of this? Thanks in advance.

The corresponding code is:

using UnityEngine;
using System.Collections;

public class DestroyByBoundary : MonoBehaviour {

void OnTriggerEnter2D (Collider2D other)


red box shows the problem inspector panel

inspector of destroyer object

  • \$\begingroup\$ Are you sure that other.gameObject is actually the root GameObject and not a child of Overlay(Clone) or Objects(Clone). \$\endgroup\$ Dec 4, 2015 at 20:32
  • \$\begingroup\$ other.gameObject is in a seperate class called Destroyer which is an empty gameObject with the edge collider and code \$\endgroup\$
    – 2hTu2
    Dec 4, 2015 at 21:09
  • \$\begingroup\$ Can you show the Inspector panel for a Destroyer object? \$\endgroup\$ Dec 4, 2015 at 21:12
  • 1
    \$\begingroup\$ There is nothing like "destroyed but still in hierarchy", if something is destroyed it gets removed from hierarchy on next frame. We need to know what is "Destroyer", what is "Objects" and "Overlay" and how you clone them. \$\endgroup\$ Dec 4, 2015 at 21:22
  • \$\begingroup\$ Objects and Overlay are both prefabs. they are called with an invokeRepeating script. Destroyer is an edge collider which destroys every Object and Overlay. \$\endgroup\$
    – 2hTu2
    Dec 4, 2015 at 21:37

1 Answer 1


You must add a Collider2D to any GameObject that is to be destroyed by DestroyedByBoundary. According to the documentation, just having the RigidBody2D isn't sufficient:

Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur.

And for 2d, specifically:

The collider types that can be used with Rigidbody 2D are the Circle Collider 2D, Box Collider 2D, Edge Collider 2D and Polygon Collider 2D

If you have the performance to spare, you should also change "Collision Detection" to "continuous".

  • \$\begingroup\$ I wouldn't suggest last line for this type of game. \$\endgroup\$ Apr 4, 2016 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .