Procedural Generation - Room NavMesh Spawning

 Author: Najee Jackson

Problem

When generating rooms, enemies didn't spawn, so the player just walked around in an empty level. To fix this, I wanted to create a spawner in each room of a certain size, but the spawner only worked in areas with valid nav meshes. My level had none in it since it was procedurally generated, which resulted in the spawner not spawning enemies, and if it did, enemies would not move since they couldn't find a valid NavMesh.

Solution

To fix this, I wanted to spawn a Navmesh Bounds Volume whenever a room was created, but I soon learned that you couldn't spawn NavMesh Bounds in Unreal Engine 5. After learning this, I searched for ways to spawn a nav mesh in a procedurally generated map. I wanted to avoid creating a giant Nav Mesh encompassing the entire map. Since I feared that the spawner would spawn enemies far away from the player, it also would be a waste of processing power to have an active nav mesh in areas that enemies never use. One way that came up was to set the NavMesh generation to dynamic so it could be changed during run time and generate the nav mesh only around invokers. This didn't work as I couldn't change the invoker's radius during run time, and the active nav mesh still went outside the room. I researched more and learned I could move already placed NavMeshes and change their size during runtime. Once I learned this, I placed ten different NavMeshes in my level and used a game instance to store them in an array. I then moved their location and changed their size when creating the room. This worked and allowed enemies to spawn within the walls of the room.


Rooms generated with no NavMeshes


Rooms generated with NavMeshes

Comments

Popular posts from this blog

Powerups and Wall clipping