Transforming a list of nodes into a navmesh graph?

Say I have a navmesh graph and I add all the nodes to a list:

List<Graphnode> nodeList = new List<Graphnode>();
AstarPath.active.data.graphs[0].GetNodes(node => {
   nodeList.Add(node);
}

Then I do some complex logic checking and assign arbitrary tags and penalty values to a bunch of different nodes.

  • How do I then take nodeList and get them back into may navmesh graph?
  • Does order matter? I would assume not because nodeIndex exists, but just want to double check.

The reason why I cannot simply run the logic inside the lambda expression is because the logic is quite complex, and must be performed on every node in the graph. Iterating through every node in the graph in a single frame leads to major framerate issues. Based on my previous thread a while ago (Work item in coroutine), work items cannot be run asynchronously. Instead, my plan is to copy all the nodes to a list, run the custom logic on the list asynchronously, then assign the node list back to the graph.

Hi

Work items can be run over multiple frames.
You do something like:

AstarPath.active.AddWorkItem(new AstarWorkItem(
   () => {
       // Init function, will be called first
   },
   (bool force) => {
       // Run one "step" of the work item. Or run everything if force is true.
       // Force will be true if someone for example calls AstarPath.active.FlushWorkItems() or tries to scan a graph.
       // This function will be called once every frame until it returns true
       // if force is true, then this method *must* return true.
       return true;
    }
);

You just assign properties to the node objects. There’s no particular order you have to care about as long as the object references are correct.

That’s the part I’m not sure about. How do I know which node in my list corresponds to a node in my navmesh graph? What would that line of code look like? Is it as simple as something like:

AstarPath.active.data.graphs[0].nodes = nodeList;

?

Hi

You don’t need to, and you should not, re-assign the node list in the graph. Only update the properties on the nodes themselves. Like

nodeList[5].Walkable = false;

Got it. The list of nodes is a shallow copy then, correct? Any changes to the nodes in the list also apply to the nodes in the graph?

If this is correct, is it possible to dump all the nodes across all my graphs into a single list, and iterate upon them that way? Since it’s a shallow copy, the reference to which graph it applies to is preserved, correct?

Yes, all the nodes are classes, so they are passed by reference.

Correct