Spawn Locations & Randomizing Spawn Waves


Will Fox

4/28/2023

Hey everyone!

This week, I do have an actual update. My team and I worked very hard to get our last boss level done with as well as buffering out the game to make sure it worked properly and ran smoothly. I mainly worked on the third boss with my group member Jamari, though. While Jamari worked on the main boss mechanics such as throwing snowballs that are attached to a spline, I worked on making the level itself and also worked on the spawn locations of enemies throughout the level. Although this seems simple - I definitely thought so - it was a little more than I originally thought. 

For starters, how do you know when the player enters the combat room? Well, this is a pretty simple answer. With a collision box. But, how do you know when the player is finished with combat? This was a little bit more complex, especially considering that we never really set up a helper function to help with encounters like these. At first, I thought of trying a method that my group mate Zak used when testing to see if there were any enemies left in a dungeon room. Essentially, what he did, was he got all of the actors inside of the collision box that is attached to the room and tested to see if there are any actors that have the tag "enemy" attached to them. If there is, then the room isn't clear. Else, it is, and the doors can open. In theory, this should work for my combat rooms in the Yeti level. But, the collision box attached to the combat room didn't actually cover the entire room. The box was set up in a way to activate only when the player has made it some distance into the room to ensure that the walls that spawn to trap the player in the room don't spawn on top of the player and make them get stuck. I would have to find another way.


These are the walls that will spawn once the player enters a combat room. They will not come down until the room is complete.

After a little more brainstorming, I discovered that using the "get all actors with tag" might be a good way of testing if there are any enemies left. If I got all of the actors with the "enemy" tag, then I can efficiently test if there are any enemies left in the level. Luckily, this worked! Whenever the player entered the combat room, the enemies would first spawn before a logic trap opened up that runs every tick to see if there are any enemies left. This is a bit of a hit to the efficiency of our game as the "event tick" node takes up a lot of processing since it happens multiple times per second. But, since we never use this node anywhere, it is fine to use it right now as there will be little to no visual changes with the game play.


Get all actors with tag

The next problem I ran into was randomizing the enemies that spawn at these spawn rooms every time the player runs into them. Essentially, whenever the player reaches the Yeti at the top of the level, they will jump onto the Yeti and deal a little bit of damage. The Yeti will then throw the player down to the bottom of the hill where they need to clear all three combat rooms again before being able to attack the yeti again. When the player attacks the Yeti three times, the player wins. But, we want to make the combat rooms different with each occurrence. So, how do we do this? Well, with hardcoding of course! Using RNG to choose the enemies that spawn in each room won't always guarantee that each room will have a unique combination of enemies. On top of that, it's dangerous as there are some enemies that can become extremely obnoxious if there is a large number of them - like the necromancer. So, the best way to make sure that the rooms were do-able and fair was to simply hardcode the enemies that are meant to spawn. 


Hardcoded spawner

I did run into a couple issues with even this, though. I originally tried to make a list of enemies for each spawn zone but Unreal didn't like this. I essentially made a list of enemybase_BP actors and then tried to store derived enemy bases - AKA the actually enemies - into the list. However, when they were stored, they were stored as "none" so this didn't work. I'm not sure why either. Usually you're able to cast a child class to a parent and then back again. But, I guess it didn't like this.

That pretty much wraps up all of the work I did for this week! To be honest, it was a little more difficult than I had imagined. But, I learned a lot about spawning mechanics and how I should and shouldn't go about doing it. In the future, I will watch some GDC videos about spawn rooms and such so that I can further improve my methods of doing this. Thanks for reading.

Leave a comment

Log in with itch.io to leave a comment.