Partial graph update during runtime in Update()

Hello,

I’m trying to do a partial grid graph update on a gameobject. The point is to update the graph around the object whenever it’s moved by physics forces:

Bounds bounds;
Rigidbody rb;

// Start is called before the first frame update
void Start()
{
    bounds = GetComponent<Collider>().bounds;
    rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update()
{
    if(rb.velocity.magnitude > .2f){
        var guo = new GraphUpdateObject(bounds);
        // Set some settings
        guo.updatePhysics = true;
        AstarPath.active.UpdateGraphs (guo);
    }
}

However, it doesn’t update the graph. Is it possible to do this frequently in the Update() function?

Thanks

Hi

I note that you are storing the bounding box at the start, but you never update it as the object moves. So your updates will always cover the same world-space area.

Fyi. There’s a built-in component called DynamicGridObstacle that does pretty much what you want. But also takes care of a bunch of special cases. You might want to give that a go.

DynamicGridObstacle works perfectly, thanks!

1 Like