How Do I Tell If An Agent Is On A Valid Grid

I need to have an alternate movement script for agents not on a valid grid. My world is too big to navmap the whole thing.

Right now the grid updates at the player’s feet. But once you move too far from an agent they can’t move because of a lack of grid below them to path with. I can’t seem to find any functions or variables that reveal this information to me so I can switch to an alternate movement script.

Any ideas?

You could get the closest point to the agent, if it’s further than a certain threshold, you can consider it being unable to move.

Alternatively you could also just check the distance to the player and disable the agent once its too far.
You could use something like https://docs.unity3d.com/Manual/CullingGroupAPI.html to achieve this.

Alright, I’ve found my solution. Looks like .GetNearest() will return null if there is no path-able graph under or close enough to the agent. In this case, I switch to my alternate movement script.

	private void IfOutsideNavmesh()
	{
		if (!arrivedAtTarget)
		{
			GraphNode node = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;

			if(node==null)
			{
				Vector3 target = TargetGameObject.transform.position;
				LookAtTarget(target);
				RunTwoardsTarget(target);
			}
		}
	}
1 Like