I’m getting an odd issue in the path finding that
if (currentNode == endNode) always returns true.
if I use : if (currentNode.GetGridPosition() == endNode.GetGridPosition()) I get the expected result that say the node at grid pos 0,0 <> 7,5
I’m also finding that “closedList.Contains(neighbourNode)” also always says the item contains the node.
What I have tried to do is add an equals operator (and the respective != etc) and compare the grid positions. This seems to show that I can compare GridPositions of path nodes but of course fails later in the code in Calculate Path where “currentNode.GetCameFromPathNode() == null” as this will fail to get a grid position for object null (trying to check for null in the override operator goes into an infinite recursion as I’m comparing it to equal and hence stack dumps, but I think that is a side issue).
I’ll look later on at writing a test case to add to this thread but wondered if someone had encountered this before?
In FindPath, I have as per the tutorial:
PathNode endNode = gridSystem.GetGridObject(endGridPosition);
PathNode currentNode = GetLowestFCostPathNode(openList);
Debug.Log(“Pre If check curr” + currentNode + " ==? " + endNode); << this returns currentNode as 0,0 and end node as say 7,5
if (currentNode == endNode) < this always returns true.
I’m wondering if the comparison is checking the object type in c# rather than the object instance ids/HashCodes?