Help understanding recast updates when placing prefabs at runtime

Hi,

I am trying to understand how to make instantiated prefabs “walkable” on a recast graph at runtime.

I am instantiating these tile prefabs at runtime which make up floors and walls, stairs, etc. on a recast graph built at editor time based on a terrain. Carving works great, when placing, but making new walkable paths does not want to work.

Each of these walkable parts have a child GameObject with a BoxCollider which has a RecastMeshObject Component and the following script.

public class UpdateGraph : MonoBehaviour
{
    private void OnEnable()
     {
         // As an example, use the bounding box from the attached collider
         Bounds bounds = GetComponent<Collider>().bounds;
         var guo = new GraphUpdateObject(bounds);
         AstarPath.active.UpdateGraphs(guo);
     }
 }

I am getting disconnected graph tiles(?) as seen in the screenshot and I am sure that i am just missing something here.

How would you approach this tile based update to a recast graph (at runtime)

Thank you all for your help!

image

Hi

It’s not quite clear to me what issue you are referring to from the screenshots. But one thing I can see is that your recast graph seems to be way too low resolution for the tiles that you are placing down.

I’d recommend reducing the “Cell Size” field, and possibly the “Character Radius” field too.

See RecastGraph - A* Pathfinding Project and RecastGraph - A* Pathfinding Project

Also. You may want to double-check that the bounding box that you get during OnEnable is accurate. The collider may not be initialized at that point. So you may want to put it in Start instead.

That’s awesome help. Thank you.

I figure that I’m not far off from getting it working. I’ll adjust the size and the method start and re-test.

The core issue i found is the graph not extending up the ramp @45 degrees, the graph is set to 60 degrees, but will update after retesting.

Reducing the Cell Size worked! Thank you so much!

1 Like