Check for clear/destroy all enemies

I have an array of random particles that need to start spawning ONLY AFTER all my enemies have been destroyed. So after the last enemy is dead (12 enemies in this case) I want the game to know that ‘all enemies are cleared’. If that’s true then start playing the spawn of my particles, if false, then don’t start spawning yet.

I thought of using an ‘is valid’ node to check if there are any enemies but so far nothing happens. I may have it setup incorrectly. In the input object I used the name of my enemy character hoping that it would look for anything in the level with the actor name. I’m probably not using it correctly. Should I also make an array for the 12 enemies and plug that into the ‘is valid?’ instead of just the actor name?

I included a pic of my level blueprint setup.

Yes. There are 174 possible target points where a burst of antiaircraft flak may occur within a grid that I setup. And there may be more. It works, but right now they all start from the moment I begin the level. I want them to only start spawning after I destroy all enemies.

I also thought of using this array as the input object for the IsValid node instead of just choosing the single pawn BP, so now I specifically list them out, but it’s still not working

Not an answer. Just curiosity - do you actually have 174 pins in the Make Array?

theres two basic ways off thr top of my head that could easily accomplish what your looking to do.

the first method would be to create an array that contains all the enemies, then when one dies remove it from the list. after that you would just need to get the array length and if its below 1 then start spawning. the script would basically be on begin play > get all actors of class (enemy) > set array (enemy list), then you would have a custom event > get array > remove array element > get array length> Length <= 0 >branch > if true spawn particles, if false do nothing. this is all off the top of my head so node names may be slightly off.

the second method you could use would be to use a timer to instigate checking if theres enemies. basically at a set interval (say 1 sec) you would get all actors of class or check the array as above.

it really depends on how you want to call an event to do the check.

as for the rest of your script thats a bit of a mess as well. using a timeline to spawn things is just a bad idea. a timeline update is kind of like tick, you will get many things spawning but it may be at a unpredictable rate. that is to say you dont have good control over things. you would be best off to use a different method such a looping timer.

Thanks. I may be misunderstanding a bit on the setup. I don’t necessarily have the nodes available to me as you described, even when I turn off context sensitive. So I tried to set it up with what I had available.

Consider looking into actor tags so you never need to connect 174 of something one by one.

your setup makes no sense logically, you were getting information via the get all actors node but then not using it. you were also getting the length of a array you were making from one value, it just makes no sense. below you will see a couple of examples that will show you the methods i described above.

in the first picture you will see that on begin play we are getting all the instances of the BP_enemy class and adding them to an array. then whenever an enemy dies we call the custom event enemy death which removes that enemy from the array, gets the length of the array, compares the length to 0, and spawns a actor accordingly.

the second picture shows another example but this one uses a timer. in this example we set a looping timer at begin play. every 1 second the timer calls the event check for enemies. we then get the length of the output array, compare the length to 0, and spawn actors accordingly as we did in the previous example. this is a incomplete script for your example but it outlines this important bits that you need, how many actors you spawn and at what rate is up to you. also note that this second example is easier to implement but is not as performant.

1 Like

The second option worked perfectly. Thank you so much!