GameObject.FindGameObjectsWithTag() Returns null although there is an object with tag

GameObject specificMenu = null;
        GameObject[] Menus = GameObject.FindGameObjectsWithTag("PlayerMenu");
        Debug.Log(Menus.Length);

it writes 0 as the menus.Length

This is the Object

Help would be much appreciated, if more info is required please ask for it

Posted in wrong forum section (see Scripting).

According to the FindGameObjectsWithTag documentation, the object must be active in order to be found:

  • Returns an array of active GameObjects tagged tag. Returns empty array if no GameObject was found.

There are several solutions for you:

  • Use direct reference to your menus

  • For UI you can let the game objects active and only disable the canvas

  • Use GetComponentInChildren on the parent game object with the includeInactive parameter set at true

  • …

Thank I will try that
I was unsure of where to post it I didn’t see scripting thanks for pointing it out for me :slight_smile:

It seems that the GetComponentsInChildren only works on active items aswell

Which the docs state. There’s an argument for it.

Look at the docs:
https://docs.unity3d.com/ScriptReference/GameObject.GetComponentsInChildren.html

1 Like

Almost everything in Unity ONLY ever considers active GameObjects.

It’s all laid out in the docs along with any special considerations, such as the special “will wake stuff up” behaviour of the collision methods.

NOTE: read it carefully, the words really have meaning. There’s a massive difference between inactive GameObjects and disabled Components.

You really will save time by starting from the official documentation on this stuff.