IsPathPossible fails with nodes seemingly in the same area


I have an issue where occasionally (maybe 1 in 5 times I run the game) nodes that appear to be connected will fail a PathUtilities.IsPathPossible check because the node.Area value they return differs. However, looking at the Graph Colouring Debug, they appear to be in the same area and are not blocked by unwalkable nodes.

If I disable my random “terrain generation” at the start of the game, I can’t reproduce, so I suspect there is something I am doing wrong there when I recalculate the graph with the new unwalkable nodes:

void Start(){
    // Create some random mountains, trees etc. IF generating a new world. TODO: an actual system.
    if (!PersistentData.CheckLoadFlag())
		// Generate mountaints.
		foreach (Tile tile in mountainSeeds)
			List<Tile> mountainTiles = ReturnNearestFreeTiles(tile, UnityEngine.Random.Range(3, 6), true);
			PlaceableController.CreateTerrainPlaceablesOnTiles(mountainTiles, (StructureObject)Database.GetFurnitureObject(5));

		// Generate trees.
		foreach (Tile tile in treeTiles)
			PlaceableController.CreateTerrainPlaceablesOnTiles(tile, (PlantObject)Database.GetFurnitureObject(6));

		// Rescan the grid graph.;


node.Area is the value used to color the graph.
Are you sure you are comparing the right nodes? Do you have multiple graphs in your scene?

Also keep in mind that running will destroy and re-create all nodes. This means that you cannot store any node references from before you called Scan.

1 Like

Thank you, the issue was “storing node references from before you called scan”. Currently I scan twice when starting the game, once on Awake() and once again on Start() after terrain gen if a new map - I skip this if loading an existing map.

I didn’t realise the nodes were destroyed and re-created on scan, so I didn’t re-run my ‘AssignNodesToTiles()’ method, leaving all the node references on my tiles out of date.

Sometimes when my agent spawns, because my terrain gen is very dumb right now the agent will spawn in the wall. But if I give a move command it will teleport out. I thought past me had written a escape function, turns out I didn’t and it was actually a symptom of the same issue! Now if he spawns in an unwalkable node he correctly gets stuck there :slight_smile:

Thanks for the help.

1 Like