Get Children of Child and Deactivate/Activate on Demand

So here is my layout, I have a 3D Menu system working and they are all in a parent/ child relationship. So for example I have my GuiRoot variable which is just an empty game object then the child of that GuiRoot is going to be my MainMenu. I then have children inside of MainMenu each child has a bunch of siblings as well so it looks kind of like this:

alt text

So when i need to transition to my next menu my camera is promted to tween to the CameraLookAt and CameraPosition. I then get the name of the Parent of the currentMoveToPosition and compare my childs name with that name which should be MainMenu( and it is) but i then need to get all of the children of MainMenu and activate them which is what i am trying with the second for each.

My Problem is that the second for each isn’t firing and I do not understand why not. The Print(“in grouping”); never gets sent and so neither does the if below. The Printing of the currentMOveToTarget.parent.gameObject.name and guiChild.name DOES however fire. and everything inside of gui gets turned off… I dont understand the issue with my code.

This is all a bit complicated and I don’t know if i explained it very well. So if you need more explanation I can expand.

allGuiChildren = guiRoot.GetComponentsInChildren<Transform>();
		
		// Turn off all GUI cases except for the Main Menu
		foreach( Transform guiChild in allGuiChildren )
		{
			print(" in gui children");
			// get the parent of the current move to target in this case it is main menu
			if( guiChild.name == currentMoveToTarget.parent.gameObject.name)
			{
				Transform[] currentGuiGrouping;
				currentGuiGrouping = guiChild.GetComponentsInChildren<Transform>();
				print(" in current Move to target" + currentGuiGrouping);

				foreach( Transform guiGroupingChild in currentGuiGrouping)
				{
					print("in grouping");
					if(guiGroupingChild.name == "GuiBase"){
						print(guiGroupingChild.name);	
					}
				}
				print(currentMoveToTarget.parent.gameObject.name + " " + guiChild.name);
				// figure out how to set the children of mainmenu true
			}
			else
			{
				guiChild.gameObject.SetActive(false);	
			}
		}

Thanks in advance!

Try:

GetComponentsInChildren<Transform>(true)

to find the transforms of inactive objects, too.

Also, you can iterate over a transform itself. So you can do this instead:

// Turn off all GUI cases except for the Main Menu
foreach( Transform guiChild in guiRoot.transform ) {...}

and

foreach( Transform guiGroupingChild in guiChild.transform ) {...}

Makes the code simpler.