This week I have done a lot of work on the environmental aspects of my game and expanded on my AI system. I have created several buildings which I have turned into blueprints. Each blueprint has a list of child actors which serve as zombie spawn points. Each one of these spawn points has a boolean variable for whether it has a spawned zombie or not. This was added because, at first, the spawner on the building would occasionally spawn multiple zombies at the same spawn point. By adding this boolean variable I have made it so the spawner can check if there is a zombie here already and if so it will check another point and keep checking until it finds a free one.
I have also made it so that the spawner will use a random combination of points for each building. I have given each building a MaxZombies variable and have placed around 2x this amount of spawn points. This way every building has a unique combination of zombies in different locations. I feel that this really helps to make the game more immersive and feel less repeated.
Originally I had set the zombies to simply spawn inside every building on the begin play event for each building. However, this was breaking the AI, causing every zombie to simply animate in place but not actually move to chase the player.
After some research I came across this post:
AI / Bot Limit? – Programming & Scripting / AI – Epic Developer Community Forums (unrealengine.com)
What was happening is that because zombies were spawned on begin play and kept active the whole time regardless of where the player was the amount of AI agents spawned was much higher than the MaxAgents stat which can be found in Unreal Engine in the project settings.
Because of this I had to make some changes to my building blueprints. I came up with an idea – instead of spawning zombies on begin play, I would spawn a structure of “zombie info”. This would include all the details I would need to cheaply create large amounts of non-spawned zombies in the world and accurately spawn/despawn any zombie based on the player’s location. This structure contained variables for the zombie’s skeletal mesh, current health value, location and which spawn point it was attached to (if any).