- Home /
is an Array the most efficent way of finding the closest gameobject?
I know the method of finding the closest gameobject with FindWithTag, but im programming a Lumberjack for a RTS who should always walk to the closest Tree.
The problem is that its a pretty big world with several thousand trees and also several Lumberjacks and im not sure if its the best way to go through the whole array every time they are searching a new tree.
Im not sure if this will acctually cause performance issues so maybe someone more experienced could answer me this Question :D
Answer by getyour411 · Aug 05, 2015 at 02:25 AM
IF your trees are actual GameObjects in the hierarchy (and not terrain trees), use Physics.Overlap sphere or other 'constrainted by Vector3.position' method.
Yes they are gameobjects, but i would need a really big sphere because maybe the player places the lumberjack far from trees or they have cutted all trees in certain are. But yea i think its always better than my current method :P maybe i then need to give the player the possibility to manually select new trees
Your answer
Follow this Question
Related Questions
Select/attack closest target array 1 Answer
Pick the oldest object from an array. 2 Answers
Get object child list with tag 2 Answers
Implicit Downcast on array object and clearing array 0 Answers
Array loads in wrong order 3 Answers