- Home /
Question about FindObjectsOfType
Hi. I'm trying to convert some code from finding objects with tag to type because unity support told me it uses less resources to do so. So my question is. If I have an array I made
private GameObject[] FloorArray;
How do I fill it?
FloorArray = GameObject.FindGameObjectsWithTag("ColoredFloor");
This doesn't work, and if I later want to remove all objects in it without Red as tag. how do I do that?
Answer by tanoshimi · Jan 22, 2014 at 07:34 PM
"...convert some code from finding objects with tag to type because unity support told me it uses less resources to do so..." - that doesn't really make any sense. The functions have different purposes - if you're trying to find all gameobjects that have been tagged with "ColoredFloor" then you need to use FindGameObjectsWithTag(). If you want to find all objects of a particular type (e.g. a HingeJoint) then you use FindObjectsOfType.
It's not a matter of performance or resource usage - they simply do different things.
Alright. I didn't understand what he meant as well(the person from support) I think he meant that I could find all gameObjects and then all of those with a specific tag or something(not sure) but that would make any sense. Thanks for clearing this up.
Your answer
Follow this Question
Related Questions
How can I make a GameObject face a GameObject with a specific Tag? 1 Answer
Get Script from gameobject knowing only parent script 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Attacking more than one enemy with same tag, but unity only allows one enemy at a time? 2 Answers