Is there a way?

I’m currently working on a Tower Defence game and are in need of a way to properly destroy/kill the AI enemies. I’ve tried using the destroy actor when either they health is <=0, but that seems to give me tons of blueprint errors(“Is pending kill”). I’ve also tried to set the actor hidden in game and changing the collision object types when “killed”. Making the enemies hidden doesn’t seem very effective in the longrun, as it will just pile up and create a big mess.

Is there a good way to make the enemies die when they either reach their goal or get killed by a turret, etc? Is it possible to do it in the Behavior tree? I’m currently using the behavior tree to navigate the enemy to the end goal location.

Try to use isvalid node on the actor that you want to destroy to avoid is pending kill errors

Generally speaking, keeping the enemies around and “recycling” them is a viable strategy, but if you’re not going to do that then adding pointer protection (aka IsValid) and then calling Destroy is appropriate.

In fact, checking any/all pointers would be a better strategy regardless of if you recycle your AI. If you can hover over a variable and the tooltip displays “SuchAndSuch Reference”, you should probably make sure it’s valid at the start of the exec chain where you’re using it.

Any suggestions on how I would set up the “IsValid” in the function that destroys/kills the enemy, starting from scratch in the function blueprint?

You’ll need a “branch” (basically an conditional if statement) and the isvalid outputs a -yes or no- to your if question…if YES…then destroy…if no…then nothing happens (leave false unplugged so nothing can happen)

You checking hp and destroying actor in tick right?
If yes, put after hp<0 node “do once” and then destroy actor, after this it shouldnt spam errors about pending kills…

How I currently have it all set up:
In the bullet blueprint:

In the Receive Damage Function (In the Enemy BP):

In the Kill Enemy Function (In the Enemy BP):

I’m also curious to know if implementing the kill enemy on reached goal function to the Gamemode is the best option. I’ve currently added the set current player heath in the GameMode, which registers when an enemy has reached the goal and then updated the player health. Correct me if I’m wrong, but I need to implement the kill enemy on reached goal in the end of the GameMode blueprint, so it doesn’t kill the enemy before it has updated the Player Health, correct?

My Player Health function inside the GameMode:

I need two ways to kill the enemy. As you can see above in the Enemy blueprint, I’ve already added the function to kill/destroy the enemy when <=0 Health, but I need a way to kill/destroy the enemy when it reaches the goal/target.

I’ve currently created a function which I will use to kill/destroy the enemy once they reach their goal/target. I’m guessing I will have to put the function after the set current player health, so it doesn’t destroy it self before the health updates?
This is how my kill enemy function looks. Keep in mind that is function will only be used when the enemy reaches his goal/target.

Here is my problem as of this moment. This function seems to be working, where the enemies die, but I’m currently receiving lots of errors which is redirecting me to the Tower.
Here you have the Tower BP:

And here you have the Error:

Error Blueprint Runtime Error: Attempted to access BasicEnemy_C_0 via property CallFunc_Array_Get_Item, but BasicEnemy_C_0 is pending kill from function: ‘ExecuteUbergraph_BasicProjectileTower’ from node: SetWorldRotation in graph: EventGraph in object: BasicProjectileTower with description: Attempted to access BasicEnemy_C_0 via property CallFunc_Array_Get_Item, but BasicEnemy_C_0 is pending kill

bump bump bump

Everytime you’re using a blue wire - - also use “IsValid”. That’s why you’re getting ‘pending kill’ errors.

Hey everyone. Just wanted to say thanks to the people who have offered their advice in this thread. I was having a similar problem and this is really useful. I had somehow managed to get rid of the Pending Kill issues in my Blueprints by changing how I called the Destroy Actor node but using IsValid is a far more elegant solution. So thanks! :slight_smile: