Hello, the problem i have is that when my AI needs to find the closest gameobject (a tree) i’m getting a huge frame drop, i know why, but can’t find a way to fix it.
At this moment when the tree spawns, it has a script (resource) based on the type its being added to a list with multiple tree’s.
To get a tree my AI runs a foreach loop trough the list and looks at which tree is the nearest with Vector3.Distance, the tree that is closest to the AI will be returned and set as destination, but the only moment its going trough the list it’s giving a huge frame drop, because the foreach loop loops trough an entire list of tree’s.
How can i find the closest tree in a clean way?
Thanks in advance,