Searched whole area but could not find target

I have this weird issue where I cannot find a path if I have a very shallow mesh collider in the way.

The player draws roads that have a 0.1m thickness. These are on top of the gridgraph. I have this issue now where I cannot find a path to target if I try to path on any area where a road has been laid.

What could be causing this?

Hi

Could you post a screenshot of your graph with a road built?

Here are two screenshots:

With collider shown:

Also, it is almost impossible to see due to the shader I wrote for this road, but this road has a pointgraph (well, custom graph derived from a point graph) that goes along its “spine”

Small update; I just added a capsule collider to by agent, and now it can’t find a path anywhere at all.

What am I doing wrong?

EDIT: N/M, it was a fluke. not sure why that happened but it is not happening anymore. still have the road problem though.

Ok so I have more info. This has nothign to do with colliders.

I have three graphs in play here: Road Graph (point graph derived), Grid Graph, and Ocean Graph (exactly like a grid graph except for like, 3 lines of code). You can see this in the first image.

I have prioritize graphs turned on. If I make the grid graph of a higher priority, it then has no problem pathfinding into that area.

The reason I have it turned on is because I would like my agents to prefer the road over the grid graph; was hoping that this would make it do that.

So with that in mind, what could be going wrong here?

Hi

Prioritize graphs does not do what you think it does.
Here is the (a bit light I guess) documentation: http://arongranberg.com/astar/docs/class_astar_path.php#a565b110e4b10f36bc9d8cb8573599a33
So your agent on the grid graph tries to find a path to a point on the road. However since prioritize graphs is enabled, it will find that the road graph is closer and pick a node on the road graph as the target node. But the road graph and the grid graph are not connected. There is no information available about how to move from the grid graph to the road graph so it tries to find a path, but it does not find one.

My suggestion is that you connect your road graph with the grid graph.
You can do this by in the Scan method of your road graph, register to the AstarPath.OnPostScan delegate to call a new method called say ‘ConnectGraphs’ (because you need to wait for the grid graph to be scanned). Inside ConnectGraphs you unregister from the delegate and then for each node in your road graph, try to connect it with the closest point on the grid graph (or a few of the closest nodes which will likely give you slightly better path quality). You can do that using a AstarPath.active.GetNearest query with an NNConstraint where the graphMask is set to only search the grid graph (the graphMask is a bitmask so if it is set to 1 << 2 for example, it will only search graph index 2, in your list it looks like the grid graph is graph index 1, so you should set it to 1 << 1).

Oooo interesting. Ok I see. I didn’t know I could connect the nodes from one graph to another!

I am going to try this right now. I might have a question or three :smiley:

As for making it more desirable to use the road graph compared to the grid graph. What you need to do is to increase the penalty for walking on the grid graph. Take a look at Grid Graph -> Initial Penalty. You need to set this to relatively high values. A value of 1000 corresponds roughly to the cost of moving one world unit.

Note that this will make path requests slower since it will have to search more nodes when the penalty is higher.

I see. So if I connect the road graph to the grid graph, and then also ensure the grid graph is more expensive; it should naturally favor the road graph?

Yes, that is the idea.

Btw. Make sure you create bidirectional connections. So you use a.AddConnection(b) and b.AddConnection(a). Otherwise the connection will only be one-way which is likely not what you want.

Once again, I am shown why this is hands down the best asset in the asset store.

Not only did you solve my bug, and give me the behavior I needed; it only took 6 lines of code to add this. I am so happy right now. Thank you! I haven’t stress tested the performance impact yet, but this is the right direction.

Hi

Awesome that it works now :smile:

PS: A rating and/or a review in the Unity Asset Store is always welcome.

Oh I think I already rated and gave a review when I purchased the other day (mine is the most recent). I had been using it for 6 months before I bought it so I already was impressed by it; I just keep on getting impressed. :smiley:

Ah, thank you for that review then :smile: