Check If All Enemies Have Been Destroyed

Greetings,

So, I’m working on enemy waves, and for a reason I do not understand, “ISVALID Index” when set to “1” comes as true when there are two enemies left (I understand why), and when set to “0” is true when there’s one enemy left.

How do I check for no enemies left? I tried “-1”, you know, to be cute, and Unreal was like, “heeeeellll no, noob.”

This is my solution, but there’s got to be a more elegant way!

(I originally used a counter, but because of duplicate pulses to ensure smooth and accurate animations, I opted for this less buggy version instead).

May be you can use “ForLoop” node.

1 Like

Try this:

As a pure function:
image

BTW: Using GetActor should return valid pointers. So what’s the point unless you check for an empty array?

1 Like

AH! Yeah, actually that makes PERFECT sense why “GetActor” would only return… well, actors.

I’ve been programming all day, so my brain is oatmeal at the moment.

Ah, this is actually the loop that I tried to create manually!

Ya, that happens with me a lot. BTW, if your issue is resolved then you can mark this as a solution.

1 Like

First, thank you for showing me the easier looping way, because the one I create without the “for loop” function was treacherous.

My concern is that it will pass a value as “not valid” before ALL enemies are destroyed.

To be clear:

Enemies 1, 2, 3 are dead, but 4 and 5 are not.

If I have a condition on the other side of the loop, would it go through as “Invalid” at some point, even though 4 and 5 still exist? (They’re using the same blueprint, which is the issue.)

it should not go as “Invalid” if enemy 4 and 5 still exists. Has it happened before?

They’re using the same Blueprint but “get all actors of class” node gets an instance of an actor of particular class, so it is checking on individual level.

I haven’t tried it yet.

I was just analyzing the code.
I will try it tomorrow, when I’m thinking more clearly, and promote your answer as “solution” should it behave identically to my solution.

most probably. Might need just a bit of tweaks in the code in your BP.

1 Like

I really don’t like using “get all actors of class”, but if you must, why not just check if the returned array is empty to know if there are enemies left?

If this node returns an array of all BP_Enemies, and all of them are destroyed, wouldn’t that return an empty array?

3 Likes

Nailed it!

Yours works, too, by the way!

Unfortunately (?) his/her solution is simpler.

Thank you!

whose?

Simpler for me, anyway. Depends on the person’s workflow.

thats actually smart

1 Like