How do I make it so that once all enemies are destroyed, the next wave starts?

It seems pretty simple, but how do I make one wave begin when all enemies of the previous wave are destroyed? I have tried setting this up properly but no success. Can someone help?

You will need to have a variable keep track of how many “enemies” you have in your level. Depending on how you get them into your level (dynamic spawning vs placed) there are various ways to get that number (“get all actors” if they are manually placed, or add each to an array during dynamic spawning). Once you have that number, each time an enemy is killed subtract one from the total, then check and see if it equals 0, if yes then you have completed the “wave” and can spawn new enemies, if not do nothing.

I tried doing that also but couldnt get it to work. Can you give an example?

Not at a computer at the moment so I can’t but if you upload screen shots of your set up I can attempt to troubleshoot.

If you’re destroying the enemy actors every time they die then run a “Get all actors of class” every time the enemy dies, and compare the return array to a Length node attached to a branch node where you will have a true and false return. If the length of the return array is == (equal to) the specified number you’re comparing against, then do something. Here’s a small example.

Edit When you run the “Get All Actors of Class” node, it only gets actors that are spawned in the world. So as long as that number is less than or Equal to the number you want, to spawn the next wave. It’ll do whatever you want it to do, off the “True” pin on the Branch Node.

You need something like this. The first image is built within the “spawning” BP. The second goes within your enemy BP. Each destroyed enemy will reference the spawner and figure out if it was the last enemy killed based on the total number of enemies spawned.

This is what it looks like after I tried to set it up following CoalFireGaming’s example which I also wasn’t able to get working.

I got it to where everytime I destroy an actor it subtracts the integer in increments, but I’m trying to make it so that if the increment goes to zero, actors are spawned in. Everytime I reference my spawner it would say that it “Accessed None trying to read property SpawnReference.” I also tried it the other way and reference the actor itself from the spawner but that accessed none also. Any idea how to set up the spawner to spawn actors from class when there are none on the map because I tried a couple different ways and couldn’t get that part.

Show me your spawner screen shots and how you decrement your enemy number. You must be deleting the spawner itself somehow which you shouldn’t. It should be persistent in your level and have your enemies reference it to determine if they are the last enemy.

I didnt set spawn reference if your talking about get or set. But I think the reason the function “Myfunction” isnt being called properly is because I put it in the ZombieMakeHuman blueprint which it is trying to be called from but cant because the ZombieMakeHuman blueprint actor is destroyed before it is called. Would I set that up in the Spawn blueprint?

It doesn’t work because you never set the spawn reference. If you print a string from the spawn reference I bet it says none…that’s why none of this works and you get accessed none errors. You didn’t give a direct reference you just made an empty variable container for the spawn type object but never put a specific object in

I try to play the function Myfunction from ZombieMakeHuman and the target is Spawn, but that doesn’t work. Maybe I didn’t set that function up right. Maybe the Event Destroyed in Spawn shouldn’t be there.

Where did you set “spawn reference”?

The “Spawn Reference” variable is the right “SpawnBlueprint” object reference. It is referencing the “SpawnBlueprint” blueprint. BTW I changed the blueprint name from Spawn to SpawnBlueprint to make sure it was the right thing to reference. That wouldnt change anything else though. Also what would I do now?

Show me how you “set” that reference

I drag off from true on the branch in ZombieMakeHuman and type in Myfunction. Then since it needed a reference because the function is in another blueprint, I promoted Target (from the Myfunction connected to branch) to variable which referenced it that way.

Ill have to get back to this tomorrow , getting off for now. But if you have any idea how to have it work right then please let me know. Thanks.

Actually I just got it to work right. All I needed was a “Get All Actors Of Class” in my ZombieMakeHuman blueprint for actor class “SpawnBlueprint” and THEN call the Myfunction.

Haha yea, that would be one way to get the reference. Glad you got it working :slight_smile: