Im somewhat new to Blueprinting in UE 5 and have been running into an issue with my Blueprint.
So I recently had the problem of enemies spawning all in at once on their spawn points which I have placed in the map. This caused major frame drops.
So after searching online, I managed to find a solution to make the enemies spawn in with a timed delay inside each wave so that you dont have to process all of them spawning in at once. This works brilliantly!
But the issue is now that if I kill any of the enemies before the entire amount have spawned in, the engine would only “start counting” the amount killed after all of them have spawned.
For example, ( Blueprint in images below ) on Int 0 there will only spawn in 3 enemies. If I wait for them to spawn before killing them, it will successfully move over to Int 1 and spawn in the next 5 enemies with the delay correctly. However, if I start killing the enemies before all 5 enemies have spawned, it wont move over to the next Int. ( I have a wave system also, but I suspect the problem is with the For Loop With Delay because this wasnt an issue before implementing it ).
How can I go about to fix this? If more info is needed, feel free to ask!
So on the second image I posted in the main post, there is an Array node which is connected to Number Of Zombies. This will give each zombie a number upon spawning.
On the enemy itself I added a check so that whenever the enemy is killed, it will remove itself from the array.
Then, there is an constant event called Wave Check running to check whenever there is zero enemies with a number in the level, and if true, it will move on to the next level.
Since you are spawning them with a delay and checking array length after each kill, it could be that it removes from the array leaving it = 0 and it moves to next wave while still spawning the remaining from prev wave?
@pezzott1
This certainly does happen yes. Whenever I kill the first enemy upon spawning, the wave countdown to the next wave will start, but the enemies from the first wave will still be spawning in. I thought this will be soemthing not to worry about too much because the spawn delay can be changed to something like 0.2 seconds and the enemies will spawn around a corner at 4 pre-set random locations so it will be kind of impossible to kill the first one without having others spawn in.
But this might be where the flaw is anyways.
Is there a chance that you might know how to fix something like this? Thanks for the help so far!
Edit: Maybe it could work if you only give a tag or something to one zombie in the arena, and if he is killed, it will check if there is any other zombies in the arena. If true, it will pass the tag over to that zombie, but if false, it wil do a Wave Check. In theory it sounds like it could work but im not sure how to implement something like this.
I suggest have an int with the total amount that will be spawned in that wave and as they are spawned, bind OnDestroy to an event that will ++ an int. When the incrementing int == total amount, then move to next wave. Like this the only way you can move to next wave is if you spawn and destroy at least the amount you intended to spawn in that wave.
If you have a boss that if killed wave is over early, then something like a dispatcher passing a string could be enough.
I would also suggest you drop that custom loop with delay and use a timer.
Then its just a matter of telling it how many waves you want to spawn.
A bit off topic but… you could also make it dependent on a data table in case you plan on spawning mixed classes and / or other wave like events. Each row with the data for each waves: