Unity-Pathfinding icon indicating copy to clipboard operation
Unity-Pathfinding copied to clipboard

If Pathfinder.FindPath argument `associatedObject` is null, path finding does not ignore invalid nodes.

Open nathanabercrombie opened this issue 5 years ago • 0 comments

If no argument for associatedObject is provided, or its null, then this check fails to check for invalid nodes, causing the path to use invalid nodes. It may also be possible to fail if neighbor.associatedObject is null, but I am not sure if that can happen.

//The associated object check is so the enemy ignores pathing through it's own bad sector
if ((!neighbor.valid && neighbor.associatedObject != obj) || closedSet.Contains(neighbor))
{
    continue;
}

Instead, I think it should be:

//The associated object check is so the enemy ignores pathing through it's own bad sector
if ((!neighbor.valid && (obj == null || neighbor.associatedObject != obj)) || closedSet.Contains(neighbor))
{
    continue;
}

nathanabercrombie avatar Apr 22 '20 21:04 nathanabercrombie