Multiple Grid Graphs Vs Penalties

Hi,
In my game, I have two different types of AI agents. Both agents can transverse the same map for the most part. However, one of the agents has a few select areas that it cannot enter.

My first instinct was to try and use one big graph and then use penalties to block areas for one of the agents. However, I’ve noticed that penalties are causing warnings to appear in the inspector about path failed and gives a recommendation to use calculatePartial although this comes with a performance cost. Looking through the forums it appears the solution was to go into the SearchPath function and the calculatePartial line like this:

ABPath p = ABPath.Construct(start, end, null);
p.calculatePartial = true; 
SetPath(p, false);

This made most of the warnings go away, but I’m still getting them every so often.

This lead me to perhaps another solution where I have 2 grid graphs (stacked on top of each other). One for one set of agents and one for another set of AI Agents. I thought this might be preferable so that the calculatePartial didn’t have to be used for all agents (since calculatePartial supposedly comes with a performance cost). I’m not sure if it is faster to have two grid graphs (one for each agent type) or 1 grid graph with penalites and all agents using calculate partial?

However, I’m running into a bit of an issue when trying to use two grid graphs of the same map. I thought I could use the graph update scene component to mark areas as not walkable for certain AI agents. However, the graph update scene component doesn’t appear to have a graph mask on it. So when it scans it updates all grid graphs instead of just a specific grid graph that I set. So if I have two grid graphs stacked it is updating the graph for both in that area, instead of just an area for a single graph.

Overall, I think using two separate graphs would be the easiest solution (especially if it is more performant than making all agents use recalculatePartial and using the penalties). I just would need a way to be able to apply a graphUpdateScene to a specific agent graph and not all graphs.

What do you suggest?

@aron_granberg Know you are super busy. I just wanted to give this post a bump in case it got lost with all the other posts. Thanks!

Hi

Yeah, the GraphUpdateScene component does not support specifying which graphs it should apply to.

If you make a custom GraphUpdateObject you can set guo.nnConstraint.graphMask to specify this.

I agree.

In the next beta version I will also add GraphUpdateScene.GetGraphUpdate which would allow you to get the GraphUpdateObject from a GraphUpdateScene component.

Thanks Aron! If I understand correctly I would do something like this in code to create a GraphUpdateObject correct? I had a few questions on the code as well as noted below.

//To make an area not walkable
var guo = new GraphUpdateObject(someBounds);
guo.nnConstraint.graphMask = 1 << 2; // Update only the third graph (index 2)
guo.modifyWalkability = true;  //Is it necessary to modify walkability? 
//Or will the collider of bounds handle this?
guo.setWalkability = false;
//guo.updatePhysics = true; //Is this line needed here as well?
AstarPath.active.UpdateGraphs(guo);

//To make that same area now walkable again
//Do I ensure the collider for the bounds is disabled only?  
//Or do I need to setWalkability to true as well?
AstarPath.active.UpdateGraphs (guo);

On a side note, I currently use the non-Beta version as I wasn’t sure if the beta version was production ready or not. Should I be using the Beta version? Is there somewhere that lists the major changes/features of the Beta version? And the process for upgrading to the beta version?

Yes.

Usually you do not need to set modifyWalkability/setWalkability. Instead, if guo.updatePhysics is true, then it will use physics to recalculate that region as if the graph was scanned from scratch.

Yes.

The beta is pretty robust. Though local avoidance is a bit in flux at the moment. It has more bugfixes than the non-beta.
You can find the changelog here: Changelog - A* Pathfinding Project
You can download the beta here: A* Pathfinding Project