Setup: I have a game where I have set up a series of prefabs, and these prefabs all have nodes (empty GameObjects for now), and some of them have SpawnPoints (workaround for nested prefabs that simply instantiate a given GameObject). all of the nodes are currently named Node#, and I can put them on their own layer, or give them a certain Tag if that will help.
desired outcome: I want to search through a GameObject, and find all items of a given name, or have a given Tag so that I can register them for access by other things.
Information: I know that GameObject.Find(string name) is slow, and only returns the first thing it finds, and GameObject.FindWithTag(string Tag) aslo only returns the first thing it finds, but is faster.
I don’t want to have to give every node, or SpawnPoint a specific layer mainly because of a cheviot of the level will by dynamically/randomly generated, so I will not know how many of these things there are. there will be constraints like knowing the dimensions of a given subspace of the level (room, and I am more interested in what is in each room then in the overall level)
Question: how do I effectively find all objects of a given name, or property within a given space that are all defined (exist as members of the prefab object)
Edit: these rooms will be chosen, and placed pseudo-randomly with a unknown amount, configuration, and type.
(following @## refers to a given room prefab/rule) one configuration could have: 5-R02, 2-R06, 7-C01, and 4-C02. this could be a small configuration, but can be seen as a trivial case. while another configuration could have: 1-R01, 1-R02, 3-R04, 8-R06, 18-C01, and 2-C04. which might be a larger, and more complex case, but still feasible with the system.
I kinda don't get what you mean by "items" "in" a gameobject, you mean the components of a gameobject? or the children of a parent gameobject? or objects within a specific space/area of the scene? If it's like space/area, maybe have a trigger object that envelops the area that manipulates tags on enter/stay/exit.
– WisearnIf you only have to do this once, you can perform a deep search using GetComponentsInChildren<Transform>(); Then, you can check each one individually. This is not ideal, speed-wise, but if you can cache the results of it you only need do it once.
– syclamothWell you could include the trigger area in the rooms that will be chosen, just like any other part of the room though? in the prefab GetComponentsInChildren would only work for children, and not your entities that won't be.
– Wisearn