Hi! I know this could be a very stupid question, but is there any way to get an array or something with all the game objects that are at base level, i mean, with no parent?
Thanks in advance
Hi! I know this could be a very stupid question, but is there any way to get an array or something with all the game objects that are at base level, i mean, with no parent?
Thanks in advance
One way would be to use Object.FindObjectsOfType() to find all objects of type GameObject. Any game object for which transform.parent is null will be a top-level object in the hierarchy.
Ok thanks! I have never seen utility for GetObjectsOfType until now
Note that it’s mentioned occasionally that FindObjectsOfType() can be slow. Whether this will matter for you or not depends on how you’re using it exactly, but I just thought I’d mention it. (My advice would be not to worry about it unless you find that, in practice, it’s causing a performance problem.)
Ok! I was planning to use it only when the game gets paused and unpaused, to notify all of them the state change. But I think I’m going to register them in one manager and access them through an array!
Thanks again for the help