Check if the path is blocked by a nav mesh obstacle.

Hi everyone,

My problem is this; I create buildings dynamically on a map but I would confirm that they do not block the way of the moving units (my buildings have the nav mesh obstacle component with the carve property set to true).

Is there a way to achieve this?

I tried with the following code, but without success:

_baseTowerObstacle.enabled = true;  // I turn on the nav mesh obstacle component to take into account in the calculation of the path.
NavMesh.CalculatePath(_spawn.position, _target.position, -1, _path);
_baseTowerObstacle.enabled = false; // I immediately disables the nav mesh obstacle component to prevent my units stay locked during the placement of my building.

if (_path.status == NavMeshPathStatus.PathComplete)
{
	// It's ok, let's build.
}
else
{
    // PROBLEM : I never go there, even when I have an obstacle in the middle of the road =/ 
}

Hi,

I have just the same problem, I’ve found a possible solution but it has its own problems :(, the way I temporarily solved it was by having the code in a coroutine and adding for example “yield return 0;” after “_baseTowerObstacle.enabled = true;” like this:

_baseTowerObstacle.enabled = true;

 yield return 0;

 NavMesh.CalculatePath(_spawn.position, _target.position, -1, _path);

Edit: Ok, so I managed to solve one problem in which the agents were stuck just by adding the folowing on the agent’s code:

agent.ResetPath ();
agent.SetDestination (target.position);

Hope this helps you at least a little.

Best regards,