Unreachable nodes in point graph

I am simulating visitors that walk along user build paths. The road is tile based so I am using point graph and randomizing their paths a little (so first question - what graph can be better for this?). When user updates road it can make some parts unreachable from start node and agents that are on those parts must be removed. What is the best way to do that? I was thinking just check if the start tile is reachable from each agent. If this is the best way - how can I do it?

Thanks a lot.


After the graph update you can use the PathUtilities.IsPathPossible method to check which agents should be removed.

You may want to call AstarPath.active.FlushGraphUpdates to ensure that the graph update is applied immediately.

@aron_granberg Thanks! That worked perfectly.

One more question - how can I get node for object? I have list of objects with tags that create graph. So can I get directly a corresponding GraphNode for some of these objects or is GetClosestNode the best option here?


No such mapping is maintained by the system. You can use GetNearest to get it. Each PointNode does have a field called ‘gameObject’ which is a reference to the gameObject that is was created from so you can do

using System.Linq;
var graph = AstarPath.active.astarData.pointGraph;
var node = graph.nodes.FirstOrDefault(n => n.gameObject == targetObject);

However that would not be particularly performant if you are doing lookups very often.

Thanks. Everything worked just fine.

@aron_granberg I believe there is a bug in AIPath.cs script.
You call virtual OnEnable from Start().So it gets called twice. For example, if I override it and subscribe to event - I subscribe 2 times.

`protected virtual void Start () {
startHasRun = true;

/** Run at start and when reenabled.
 * Starts RepeatTrySearchPath.
 * \see Start
protected virtual void OnEnable () {
	lastRepath = -9999;
	canSearchAgain = true;

	lastFoundWaypointPosition = GetFeetPosition();

	if (startHasRun) {
		//Make sure we receive callbacks when paths complete
		seeker.pathCallback += OnPathComplete;