check for all tags in a main gameobject ( children of children )

Not sure Where i go wrong but everything i tried doesn’t work so far… Maybe I need some sleep :slight_smile:

I have a checkpoint script that makes a reference to a 'main gameobject"
In this main object are a few corridors, doors, windows etc ( most of these have various subchildren )

( For example a corridor holders 3 doors, but the doors are made out of a gameobject as the frame, and then the doorwing itself )

I’d love to have a list of all those prefered “tags” so i can check their own variables
For example when a door/drawer is open or not.

I’d like to do it this way, as i then can easily send an array over to PlayerPrefsX ( unity wiki ) to save the current state of 'that specific" room / hallway etc when the player hits a checkpoint.

WHERETOCHECK is the main gameobject i drag in from the inspector.

This script works only for a first level.
My issue is that I’d love to have a script that goes as deep as it needs to find a tag; as certain objects in the WHERETOCHECK are 3 sub-children or more deep.

foreach (Transform kid in WHERETOCHECK.gameObject.transform) {
				Debug.Log ("kid tag: " + kid.transform.tag);
				//todo: looking for a way to find a specific tag fe "door"  + store to an array
			}

Thank you for your insight.

You can use the method “GetComponentsInChildren” and look after the “transform” component because there is only exactly one component of type transform in each game object.

Then loop on the resulting list and check their tags.

Thank you! That helped wonderfully

Here’s the code if someone ever needs this too:

private Transform[] objects;
			objects = GAMEOBJECTOCHECK.GetComponentsInChildren<Transform>();
			foreach (Transform myobject in objects) {
				if(myobject.tag == "door"){
					//do stuff
				}
			}