Remove a dead enemy from the array

hi

i need to remove a dead enemy from the array
i dont use destroy actor (then its removed utomaticly from the array) because i want the body of the enemy will stay in the level.

any help will be appreciated

thanks in advance

leo

Branch, HP <= 0, Remove from array

Why? Unecessary loop. He should already have a ReciveDamage Event and thats where he Performs the check against a single enemy (we know who died) only if the Event occours that could lead to his dead.

hi

thanks you for your answer, but i didnt manage to do it(new to ue4)
here is my blueprint, maybe you can tell me what am i doing wrong here

thanks
leo

You almost got it. That empty pin below your array reference is should be the character you want removed. There is a node called self which is the one you want (I’m pretty sure).

First please add your Screenshots to the main Post next time, you make it harder for People to help you by letting them search for additional Information.

Now to your Problem: Sry but that wont work. You need to have a dedicated array that tracks your Enemys. Get All Actors Of Class will always return all of them if you call that node again. So trying to remove something from this Function output is pointless.

Create a Array of your Enemy Type somewhere every of your Enemys has easy access to. Usually GameState, GameMode, GameInstance, etc are easy to access from anywhere. On Begin Play of your Enemy BP get this Array and Add self to it. On the Part where you check if health is bellow Zero you get that Array again and remove self. Simple enough I hope =)

If you are new and have trouble how BP Communication works this Training Video get you up to speed. Blueprint Communications | Live Training | Unreal Engine - YouTube

hi nachlmahr

thanks a lot, its working perfect know, with your help :slight_smile:

thanks a lot

leo

You could do this in a tick function if you want it to be very robust. Or you could have the actor call it in it’s death handling function. Here is some pseudocode of how it may look:

 for (int i = 0, i < enemies.length(), i++)
    {
        if (enemies.at(i).health <= 0)
        {
            enemies.remove(i);
        }
    }

Like I said you could place this in tick that checks everyone, this is very robust solution that will never leave a dead unit in the array – ever. There could potentially be an error that get propagated down where a receiveDamage Event might not be fired and a dead actor is left in the array.

I personally would do it the way you suggested and avoid the loop. You already posted that solution so I offered an alternative.