[Question] AI Navigation in a Procedurally Generated Environment?

Question

Hey guys!

Curious to hear your thoughts on the best way to handle AI navigation in a procedurally-generated game environment when the environment doesn't know how large/small or what direction it will be built in.

Should we be looking to create one Nav Mesh volume large enough to encompass everything? A separate Nav Mesh for separate tiles? Can the Nav Mesh be edited dynamically to match the level bounds? Any pointers here would be awesome! Thanks!

Posted Jun 3, 2016, 2:51 AM UTC

66
luthage•

You'll need to turn on rebuilding the navmesh at runtime: Project Settings > Engine > Navigation Mesh > Run time > Rebuild at runtime

Can the Nav Mesh be edited dynamically to match the level bounds

The nav mesh volume can be edited.

Should we be looking to create one Nav Mesh volume large enough to encompass everything? A separate Nav Mesh for separate tiles?

I would suggest going with 1 volume.

2
offset_filterOPIndie•

Thank you! Excellent insight.

I would assume we should also be looking to edit the bounds of other important volumes like Lightmass Importance and others through the level blueprint or C++?

1
woppin•

With dynamic navmesh rebuilds, if you're using procedural meshes they won't trigger rebuilds, so that's something to be aware of, and there's an answerhub explaining you also need to trigger an update manually when changing the navmeshboundsvolume:

Answerhub on navmeshbounds updates

Example:

  if (GetWorld()->GetNavigationSystem()->MainNavData != nullptr)
  {
      TArray<AActor*> Actors;
      FVector LevelCentre = (MinBounds+MaxBounds)*0.5f;

      UGameplayStatics::GetAllActorsOfClass(GetWorld(), ANavMeshBoundsVolume::StaticClass(), Actors);
    
      if (Actors.Num() > 0)
      {
          ANavMeshBoundsVolume* NMBV = Cast<ANavMeshBoundsVolume>(Actors.Last());
          if (NMBV != nullptr)
          {
              NMBV->SetActorLocation(LevelCentre);
              NMBV->SetActorScale3D((MaxBounds-MinBounds+FVector(0.0f, 0.0f, 100.0f)));
              GetWorld()->GetNavigationSystem()->OnNavigationBoundsUpdated(NMBV);
          }
      }
  }

The lightmass importance volume won't do anything if your level is procedural - you'll need to turn on all the dynamic lighting switches and turn static lighting off. The performance penalty for this is extremely high. There's a good set of options for making things not look awful here

2
offset_filterOPIndie•

Interesting. Even with prefab room tiles and a base three-point dim lighting setup using toned down directional lights? Entire game takes place indoors in a dungeon. The prefab tiles all have torch BPs in them that contain a point light.

1
woppin•

As far as I know, you can't use static lighting with dynamically placed meshes. There's tons of people asking the same question because they're all making ARPGs and I'm yet to see any particularly positive answers. Either the levels are static and you get static lighting, or you do dynamic levels and have to use dynamic lighting. Even small changes like knocking down a wall in Fortnight required the DFAO technique linked in that thread.

1