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
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
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);
}
}
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.
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.
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 ![]()
thanks a lot
leo
I was doing the most with my own solution. Nachtmahr’s was really a gem. I can’t believe I hadn’t considered it sooner.
You want to keep the dead enemy’s body in the level (ragdoll, etc.) but remove it from your “alive enemies” array. This is very common.Best Solution:When the enemy dies, manually remove it from the array instead of destroying the actor.In Blueprints:
On the enemy’s death event (or in the On Death / Event Any Damage when health ≤ 0):
Get a reference to the array (usually stored in Game Mode, AI Manager, or Player Controller).
Use Remove Item node → plug in the enemy reference (Self).
Optional but recommended: Also call a function on the enemy like Set Dead or Disable AI so it stops thinking, attacking, etc.
Alternative / Cleaner Approach (Recommended):Instead of removing one by one, you can periodically clean the array of dead actors:
Create a function called CleanDeadEnemies:
Loop through the array backwards (important!).
For each enemy, check if Is Valid + Is Dead (use a boolean variable on the enemy).
If dead → Remove Index at current index.
This way you can call the cleaning function after each death or every few seconds.Quick Tips:
Use Weak Object References in your array if possible (less risk of keeping actors alive unintentionally).
After removing from the array, you can still do things like:
Disable collision
Turn off AI / Behavior Tree
Start ragdoll (Set Physics Simulation)
Destroy after a delay (e.g. 30–60 seconds) if you want to clean up later.