Procedural Generation - Spawning Actors and Enemies


A large portion of procedural generation is spawning enemies within the generation and Actors/objects to fill up space. The main issue with spawning is not the spawning itself but ensuring the rooms are still path able and that enemies are accessible and work. Since I made my dungeon with tiles, I could gather every floor tile within a room. I then removed all the floor tiles connected to the doors to ensure that nothing spawned right in front of them. Next, I worked on generating static actors/objects within the level. To remain path able, I checked every tile around the object and the tiles the object took up and ensured they were usable. Next, I removed the tiles where the object spawned from the array. I got the tile using a random stream from the array. 

However, a major flaw was that the dungeon improperly removed the wrong tile. To debug, I drew every tile within a room to ensure I was getting all of the tiles and getting them correctly. The output showed I was getting them correctly; however, it was different when I tested the usable tile array. The function even showed the player spawn location was improperly removed. I ensured that I removed an item from the array correctly, but I could not wrap my head around why I was getting different variables for what was being removed and the location of the objects. I ensured my math with scaling was correct, and while doing so, I looked at where I was getting my random variable. I was never saving the random variable; instead, I recalled the get random when I went to remove the item from the array. I hurriedly saved the original random locally and used that to withdraw from the array. That ensured I was removing the correct location, and when I tested the function, it worked great.

Using the new Usable Tile array, I could spawn enemies quickly and ensure that the dungeon generated them at an appropriate, available location. Another issue was that enemies were not moving. After some research, I changed from spawning the enemies as an actor to a pawn to allow the AI to connect. However, I still need to fix my issue. After much debugging, testing, and reworking, I could not get the NavMesh to spawn dynamically. I changed the settings to support dynamic changes in the NavMesh, which helped with pathing later but did not solve my issue. After much research, I learned that my time was in vain because Unreal does not support NavMesh spawning during runtime. Instead, I had to create a NavMesh object scaled large enough to fit the entire dungeon regardless of generation. A premade NavMeshBounds was the only way to get the AI working and moving.

Leave a comment

Log in with itch.io to leave a comment.