[SOLVED] How to find all gameObjects with a certain component

I want to deactive all the canvases in the scene (that aren’t children) and activate the one in a gameObject variable

I know about Object.FindObjectsOfType<Canvas> but I can’t change their active since it’s not a gameObject

Every component has a .gameObject property.

2 Likes

Just be aware that the FindObjectsOfType method is very slow.

foreach (var canvas in FindObjectsOfType<Canvas>())
    canvas.gameObject.SetActive(false);
2 Likes