Destroy specific child object

Got a situation here that’s not so unique I think. Lots of similar questions, but all somewhat different. Be great to have an answer.

I need to destroy a specific child object on command of the parent.

A little background:

6 walls surround a Node. Node is the parent, has an array[6] that says which walls are supposed to be removed during the level build process.

  • I cannot use Transform.Find(), because while the walls of one node all have different names, every node’s walls use the same set of names. Unless I’ve misunderstood how .Find works.
  • Tried to use a for/in to delete the walls, but all the other questions similar to this have told me it can delete the parent, and anyway it deletes children indiscriminately without some spaghetti code.
  • Tried to use GetComponentInChildren with a destroy script, but targeting the right child wasn’t working and it was hitting walls that hadn’t been built by the generator yet and throwing exceptions for missing targets.

If anyone has a simple, straightforward solution, I would greatly appreciate it.

Transform.Find will only find children of a transform so your unique names should be fine. Another choice would be to add a script that identified the wall using an int or an enum so it was easier to find with GetComponentsInChildren.


    for(var wall in something.GetComponentsInChildren(WallIdentifier))
           if(wall.type == WallType.topWall)


    enum WallType { topWall, bottomWall, leftWall, rightWall, frontWall, backWall };
    var type : WallType;