First of all thank you for your time, second I’m sorry, I forgot to post that I have found a solution. To make a problem as understandable as possible I will run you through my process of finding closest object. First I will pass dictionary with positions as key and object as value so when I find closest position I know what object that position belongs to, btw because it’s a grid based graph so I never want to search for center of object but surrounding positions, some times positions above or under, depending of object type, so for one object I have minimum 4 positions. Then if I pass those positions to pathfinder it would return a path to closest position, then I would use endPoint of that path to get its object from dictionary. With Max Nearest Node Distance different from 1 sometimes I would get endPoint that it was not passed as searchPoint and as a result I would not be able to find in dictionary object for that position, then I realized that multi path also has chosenTarget property and that solved all my problems, now my Max Nearest Node Distance is 2 and it’s high enough to get agents out of carved node and low enough for them not to chose some node that its not passed and I’m ok with some little offsets for slopes or stairs.
Here is a code that I use for closest object search.
private ClosestWorldObject<T> FindClosestObject<T>(
Dictionary<Vector3, T> locationItemDictionary) where T : WorldObject
if (locationItemDictionary.Count == 0)
bool pathExists = false;
Vector3 searchArray = locationItemDictionary.Keys.ToArray();
MultiTargetPath multiPath = this.seeker[agent].StartMultiTargetPath(
(Path pathCandidate) =>
pathExists = true;
int pathIndex = multiPath.chosenTarget;
return new ClosestWorldObject<T>(
ClosestWorldObject is just a struct with two fields object and calculated reachable position.
WorldObject is a class that contains fields : center position of object, list of positions that I would like to be reachable for that position and cached GraphNodes for those positions so I don’t have to call GetNearest every time I want to check IsPathPossible for agent and some position.
I have just one question, do I even have a benefit of filtering positions with IsPathPossible before passing then to pathfinder?
Sorry for long post but I like to be as understandable as possible and once again thank you for your time and effort.