Recast Graph and Point Graph Interaction

Hello All,

Several years ago, when first starting our project, we set up a recast graph for our AI (RichAI and Seekers).

We also use NodeLink2’s to connect our graphs up and down ladders and through narrow doors. I assume they add nodes to a point graph that sits along side the recast graph in the interface.

The seeker.traversableGraphs is set to only the recast graph (graph0)


Last week we decided we waned our “brute” AIs to ignore one layer of meshs and just walk right through them as if they were not there. We created a new recast graph and set it to ignore that layer.

We set the seeker on this AI to use the new recast graph (graph 2)

The AI’s walk around on the new graph and look great smashing though the ignored layer.

But the new AI’s don’t seem to traverse the off mesh links.

Nobody on the team can remember how the AIs that use graph 0, the original graph, make use of the NodeLinks in the ladders and doors.

ie: the RichAI.onTraverseOffMeshLink event is not getting called.

how do you get a seeker using graph 2 to traverse our off mesh links?

Here is a followup

You can see in this screenshot some node links are connecting to graph 0

This second screenshot I have hidden the connections on graph 0 and showing the connections on graph 2.
You can see they seem to not connect.

Any advice about how we can get NodeLink2 to connect to all graphs?

OK what I have done is changed NodeLink2.Apply to iterate each graph, looking for the nearest link.


public void Apply (bool forceNewCheck) {
			//TODO
			//This function assumes that connections from the n1,n2 nodes never need to be removed in the future (e.g because the nodes move or something)
			NNConstraint nn = NNConstraint.None;
			int graph = (int)startNode.GraphIndex;

			startNode.SetPosition((Int3)StartTransform.position);
			endNode.SetPosition((Int3)EndTransform.position);
			
			RemoveConnections(startNode);
			RemoveConnections(endNode);

			uint cost = (uint)Mathf.RoundToInt(((Int3)(StartTransform.position-EndTransform.position)).costMagnitude*costFactor);
			startNode.AddConnection(endNode, cost);
			endNode.AddConnection(startNode, cost);

			for (int i = 0; i < AstarPath.active.graphs.Length; i++)
			{
				if (i == graph) continue;
				nn.graphMask = 1 << i;

				var info = AstarPath.active.GetNearest(StartTransform.position, nn);
				connectedNode1 = info.node;
				clamped1 = info.position;

				info = AstarPath.active.GetNearest(EndTransform.position, nn);
				connectedNode2 = info.node;
				clamped2 = info.position;

				if (connectedNode2 == null || connectedNode1 == null) continue;

				//Add connections between nodes, or replace old connections if existing
				connectedNode1.AddConnection(startNode, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude*costFactor));
				if (!oneWay) connectedNode2.AddConnection(endNode, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude*costFactor));

				if (!oneWay) startNode.AddConnection(connectedNode1, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude*costFactor));
				endNode.AddConnection(connectedNode2, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude*costFactor));
			
			}
			
		}

Let me know if you think this is a bad way to go about the problem.

I’m a little concerned we have connected our two graphs, but the AI seem to be sticking to their correct graph and not changing graphs as the move across a node link.

Hi

Yes, you have found the correct solution.
Well, ideally you’d have two separate node links which are connected to their own graphs.

I’m currently working on some updates to the node link system which would allow you to specify the graph which a node link should affect.