Hello everyone,
For our game, we have different navmesh requirements for different levels. For some, we want Static Navmesh generation, and for others, we want it to be Dynamic.
We have a commandlet which runs nightly to build the navmesh for each level, so I figured it would be fairly simple to just change this value, and run the build, but I can’t seem to find a way to actually change the RuntimeGeneration mode, and make it stick.
I see in Project Settings > Engine > Navigation Mesh, the option to set the Runtime Generation is in there, but I’m not sure how to modify that in C++. I had tried to create a new NavigationSystem, add it to the world, then create/extract the RecastNavmesh actor, set the RuntimeGeneration member on it (I had to add on a new SetRuntimeGeneration
function, as the member is protected, then build navmesh, but when I do this, whatever value I set is ignored. When I load in the map, I can see a RecastNavmesh actor in the world with whatever values are stored in Project settings, not what I had set them to before building Navmesh.
Here’s my code for trying to do this:
// Add a Navigation System to the world
AWorldSettings* WorldSettings = World->GetWorldSettings();
UNavigationSystemConfig* NavigationConfig = WorldSettings ? WorldSettings->GetNavigationSystemConfig() : nullptr;
FNavigationSystem::AddNavigationSystemToWorld(*World, NavSystemRunMode, NavigationConfig, true);
// Get the ANavigationData from the new Nav System
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(World);
INavAgentInterface* NavAgent = Cast<INavAgentInterface>(World);
ANavigationData* MainNavData;
if (NavAgent)
{
MainNavData = NavSys->GetNavDataForProps(NavAgent->GetNavAgentPropertiesRef());
}
else
{
MainNavData = NavSys->GetDefaultNavDataInstance(FNavigationSystem::Create);
}
// Create a RecastNavMesh actor from the ANavigationData, set the values we want.
// Set those back into the NavigationSystem, then build navmesh.
ARecastNavMesh* NewRecastNavMesh = Cast<ARecastNavMesh>(MainNavData);
// new function I added to access protected type
NewRecastNavMesh->SetRuntimeGeneration(ERuntimeGenerationType::Dynamic);
NavSys->MainNavData = NewRecastNavMesh;
NavSys->Build();
//FNavigationSystem::Build(*World); //also tried building navmesh this way
Am I completely off base here? Should I try setting the Project Settings instead? Nothing immediately jumped out at me for modifying that via C++.
Any help would be appreciated!