[Solved] Set tags to children of an instantiated parent

Like the title says, I'm trying to figure out how to set the tags of all the children of an instantiated parent object.

My current code looks like this right now:

void Shoot() {
var newBullet = Instantiate(bullet, transform.position, transform.rotation);
newBullet.tag = "PlayerBullet";
}

This is as far as I've got, and it works for giving the parent the tag, but I'm trying to tag all of the children instead. The parent does not need a tag. Thank you :)

foreach (Transform t in newBullet.transform)
{
    t.gameObject.tag = "your tag here";
}

This would only get the parent and the first layer of children. You can make it recursive to get the children of children if you need.

1 Like

Awesome, works perfectly :) Thank you!

1 Like