Add Rebuild Dirty Areas(only) for NavMesh in c++

Currently via c++ I’m using a queue to spawn in a NavModifier for a path for multiple AI, and using a timer to space them out so that they can account for each others’ paths.

To account for the NavModifiers spawned in, the navmesh first has to update. Therein is my issue, where some paths are being found before the mesh has been modified.

My solution: To add a dirty area to the navmesh after the NavModifier is spawned, and then immediately rebuild the dirty area before the next AI gets their path. Here is code for how it could be done:



    //TODO Figure out what the flags/represent
    NavSys->AddDirtyArea(NavModifier.GetBoxBounds(), 1);

    ANavigationData* NavData = NavSys->MainNavData;
    if (NavData)
    {
        NavData->RebuildDirtyAreas(NavSys->DirtyAreas); //Unfortunately NavSys->DirtyAreas is inaccessible outside the class
    }


The problem is NavigationSystem:: DirtyAreas are protected. If I were working in source I could just add a helper function that does the above (minus adding dirty area). For now I have to use a console command “GetWorld()->Exec(GetWorld(), TEXT(“RebuildNavigation”));”

I could create a DirtyAreas variable and pass that (possibly, haven’t tried), but I would like to be able to rebuild any other dirty areas, since my pathfinding depends on them.
Currently, I’m hackily calling a console command from c++ to rebuild navigation, but I’d rather just streamline the build to only dirty areas.