RecastGraph null reference in GetNearest on/around UpdateGraphs

Hi all,

I’m trying to prototype a game that procedurally generates a level by assembling modular chunks in a mostly linear fashion as needed during runtime, but first I’m simply testing what it takes to update a portion of my RecastGraph during runtime.

To test this out I’ve hooked up a button to call UpdateGraphs on a sub-region of a static scene. Everything works fine as the graph is updated, unless my player object resides within this same sub-region and is moving around. My player script regularly calls GetNearest to sanitize player movement (overkill for simple player movement I’m sure, but I need navigation sorted out for AI later anyway and I don’t want to use a traditional collider-based approach for reasons I won’t get in to), and I’m getting null reference exceptions from these calls for maybe the 20 frames following the UpdateGraphs call. INavmeshHolder in TriangleMeshNode.GetClosestPointOnNode is the null reference being operated on that’s causing the exception.

Can someone explain why this is happening or what I can do to prevent it? Even if the calls to GetNearest are preceded by FlushGraphUpdates (which should block until all pending updates are complete, I believe), the problem remains. Ideally any affected nodes would be cached or something so that proper player movement could continue during the updates, and only once the update was finished would anything swap over.

Am I even on the right track regarding stitching a bunch of modular level pieces together? My initial thought was to start with one module, and as the player progresses and completes whatever tasks are necessary to move on, a new module would be instantiated and positioned/aligned to match up with an exit point of the previous module. From there the graph bounds would be extended, updated based on the bounding box of the new instantiated module, and at the same time a previous module from further back could potentially be removed. Anyway that’s probably for another thread.

Thanks.