Can I verify if a path is feasible without placing an actual object in it?

I am making a tower defense game where you can place towers and walls, effectivelly creating the maze of the enemies, but I don’t want to let the player place an object in the map if it blocks the last available path to the goal.

Given the docs, I can do that using this code, which places the object in the map.

if (GraphUpdateUtilities.UpdateGraphsNoBlock(guo, spawnPointNode, goalNode, false)) {

And then removing the tower/wall from the map if the result is false.

However, I want to do a real time scan, and update the player’s cursor to red, so they can know instantly they can not place a tower/wall there. The current use case only leads to a poor user experience because they have the feedback after trying to place the object.

As a workaround I am planning to have two graphs, the main one, and then one that interacts with the player’s cursor and the objects in the map. And then run that code every time the user moves, but I assume the performance will be very bad, especially because I can have up to 4 players.

Any ideas? Maybe I missed something in the docs (game is 2D btw)


Hi, I would recommend that you use the ITraversalProvider, by which you can control the walkability of every single node without updating the graph. when you are testing if the path is still feasible you just do a real-time scan and the object to place should be taken into account in your custom ITraversalProvider.CanTraverse()

That’s exactly what the UpdateGraphsNoBlock function is for. The idea is that you’d instantiate the object, run the function (with alwaysRevert=true), and then remove the object, all in the same frame. The user would then not see anything except that the cursor turns to red (or whichever effect you want to use). You could run this for example every 0.1 seconds while the player is trying to place a building.

@ffbh’s solution would also work, and will not require you to instantiate an object. Though it requires a bit more work to manually define the nodes which will become unwalkable