Dynamic NavMesh Generation not working in Packaged Project

Hello everyone!

I have come upon a rather frustrating problem which I am almost certain might be a bug. However I’d like to confirm that I didn’t screw up somewhere along the way.

I have been generating NavMeshes on Runtime for a procedural dungeon. For this purpose, The runtime navmesh generation inside the project settings is set to “dynamic”.

Upon spawning a room, the following code is executed :

if (m_bNavigationNeedsRebuild) {
		// Build navigation
		FActorSpawnParameters SpawnInfo;

		FVector location = m_boxVolume->GetComponentTransform().GetLocation();
		FRotator rotation = m_boxVolume->GetComponentRotation();
		FVector scale = m_boxVolume->GetScaledBoxExtent();
		m_currentNavMeshBoundsVolume = Cast<ANavMeshBoundsVolume>(GetWorld()->SpawnActor(ANavMeshBoundsVolume::StaticClass(), &location, &rotation, SpawnInfo));

		UBrushComponent* Brush = m_currentNavMeshBoundsVolume->GetBrushComponent();

		Brush->Bounds = FBox(location - FVector(scale.X, scale.Y, scale.Z), location + FVector(scale.X, scale.Y, scale.Z));
		
		GetWorld()->GetNavigationSystem()->OnNavigationBoundsUpdated(m_currentNavMeshBoundsVolume);
		
		m_bNavigationNeedsRebuild = false;
	}

The rescaling of the brush happens in order to adapt the size of the navmesh to it’s parent blueprint.
This method works very reliably inside the UE 4.16.1 Editor. However, as soon as I package the game (Win 64x) all my AI Agents refuse to walk around. Typing “show Naviation” into the console reveals that there is no nav mesh, and “Rebuild Navigation” doesn’t have any effect whatsoever.

Is there any possibility that maybe unreal ignores the RuntimeGeneration: Dynamic flag when packaging?

Best regards and thanks in advance for any ideas you might have.

Found a solution to this?

I found a workaround for it. It appears that if the packages scene contains at least one navmeshbounds actor that is not dynamically spawned it works. Also, the above code will invalidate any navmesh outside of the brushes boundaries so watch out for that, otherwise some ai‘s might get stuck when creating new nav meshed areas. I was lucky in that I only needed the nav mesh to work within the room the player was currently in, if you are dealing with bigger areas where traversal between dynamically generated chunks is wanted you will have to work from a single bounds object and change its size instead of spawning new bounds for each chunk. Hope that helps

1 Like

Thanks!
The moment I deleted a bunch of nav meshes they started building again - before that they just didn’t do anything unless I moved them, but then only this one mesh built its paths and all the others didn’t.
Now I just cover large areas with one mesh instead of lots of little ones and it works.
Strange though.