[SOLVED] 2D - Runtime graph updates always one iteration behind

Trying to build a 2D prototype where you can move an object with a collider from one place to another, and the graph should update to reflect the change. The initial scan on Start works, but things stop working correctly once I’m asking it to update at runtime.

I’ve tried various methods of updating a graph at runtime, but no matter what I try the graph always seems to be one iteration behind where it should be. I’ve tried:

GetComponent.Apply()

AstarPath.active.Scan()

AstarPath.active.UpdateGraphs()

I’ve got ‘BatchGraphUpdates’ set to false on the Pathfinder component.

Each time the graph updates, it seems to execute the changes from the last world state rather than the current one. It’s always one step behind. I know I’m missing something simple, but for the life of me I can’t figure it out.

I thought I had scoured the forums for answers already, but some topics were suggested to me that seemed to describe similar problems. I was able to solve this with help from the following two posts:


  • Calling Physics2D.SyncTransforms() just before calling the graph update
2 Likes

I was scouring these forums as well looking for why my moved, scaled gridGraph in combination with my instantiated collision2d boxes weren’t being scanned programmatically. Hitting the Scan button worked fine, but somehow it never worked in code. Add Physics2D.SyncTransforms() fixed this problem for me, manually resyncing.

Thanks Skeletoneyes and Aron!

1 Like