Checking if path is obstructed?


I have a standard grid setup, agents are spawned in walking down a lane, the user places down towers that obstructs the grid making the agents move around the tower, like a maze building game.

I am trying to implement that a user can only place down a tower if that tower doesn’t obstruct the agents ability to create a path to the end. A collider is spawned before the tower that obstructs the grid, then the tower is placed upon the collider.

What I tried:
User tries to place tower, colliders are spawned obstructing the graph, I have a GameObject as an agent that’s immobile(like a path checker), I tell it to calculate path, I check if that gameobject has a path, then it can place tower, if not, warn the player.

This doesn’t work, it just places the towers, I am not sure I am using the function correctly, do you have any tips and ideas on how to solve this problem, I’m thinking there should be quite an easy solution to this…

I would love to hear your ideas, and I’m sorry if this is a question that I should’ve been able to solve myself!


There’s an API for that! :slight_smile:
Check the bottom of this page which shows you how to achieve this:

I’m sorry that I’m bothering you again, but I’m having a few problems!

Whenever an invalid placement occurs it’s stopping the placement like it should, however, I’m unable to place towers anywhere on the map after the occurance, its marking them as invalid placements, the agents who are continuously spawned are just walking blindly into the towers and disappearing, and then later on stopping from moving completely since they won’t detect a walkable path, after selling one of the towers, the agents are now properly walking through the grid, and I can now place towers, however if I try to block it, it won’t detect an invalid placement.

The logic of how it works:

//Place Temporary Collider
// If placement of collider is valid
    // Place Tower
    // Delete Temporary Collider
// Else
    // Teleport collider away and delete it. (If I don't teleport the collider away then the grid sometimes won't update, and the grid will still be obstructed)

If you’re not able to help me I’ll understand, I’ll see if I can fix it tomorrow if you have any ideas on what I can do instead I’d love that.

var guo = new GraphUpdateObject(node.GetComponent<Collider>().bounds);
var spawnPointNode =;
var goalNode =;

if (GraphUpdateUtilities.UpdateGraphsNoBlock(guo, spawnPointNode, goalNode, false))
    // Logic
    // Logic


Ah. You might have to call Physics.SyncTransforms() after you have created the object and after you are moving/destroying it. Otherwise the physics engine might not be up to date when the grid queries it.
This has been fixed in the current beta, but not yet in the released version.

I also find that setting a collider to trigger instead of disabling it works better :slight_smile: