Download

Destroy spawned projectile after kill enemy

Hello friends,

I have one thing to do that I just cant figure out how to do it in Unreal.

I have a enemy (archer) that spawns a projectile when player comes close.
Everything it’s working fine except sometimes I kill the enemy as soon as it spawned the arrow.

What I want is:
In the enemy blueprint node before I kill it (destroy actor), I get the last projectile (arrow) spawned by this enemy and detroy it too.

I need a way to connect each enemy to every projectile that he spawns.
And I have a lot of same blueprint enemies (archer) in the map and a lot of arrows spawned for each enemy.

Thank you very much!

Why do you want to destroy the arrows while they are still flying? Or do you want to destroy them after they hit something? Easiest way would be just to destroy the arrow automatically by itself, after a certain timespan.

Its a paper2d game…the archer spawns the arrow and it starts stopped in the archer while he do the pre-attack animation (pulling the arrow rope), when it animation finishes, the arrow starts to move of X velocity using a delay from the begin play of arrow blueprint.

But, sometimes you kill the archer before he finish the pre-attack animation and the arrow just go from X velocity after delay. I need to destroy this arrow if the archer that spawned it die.

thanks

WOW I just got a idea.

If I put this projectile inside the archer blueprint instead of a blueprint apart…then I will get this…right?

I guess your problem is mainly due to collision checking. Just make sure that the arrow ignores collisions with its owner

I would use an index system like i call it myself. Basically every archer and arrow have a number assigned to them so archer with index 3 spawns arrows with index 3. Then when you use ‘get all actors of class’ and call the ‘DestroyArrow’ event i would pass through the archers index. Then compare archerindex and arrowindex to determine the arrows you want to destroy. When spawning arrows also pass through the archerindex and set the arrowindex.

Just one arrow? Don’t you have a reference of the last spawned projectile right where you spawned it, perhaps, in your enemy BP? Then just destroy it.

Couldn’t you also just create a Boolean variable for something like isALIVE? and default it to true. When the archers die set the boolean to false. Then for the shoot mechanic check the value of the boolean first. if the archer is alive animate and finish shooting and if isALIVE? is false destroy the protectile.

You can still keep the arrow in a seperate BP, spawn the arrow blueprint inside the archer blueprint and store a reference to the arrow/s in your archer. On archer destroy() loop the arrow references and destroy.

Thank you very much my friends for the reply! Amazing. I will try to keep it on separated blueprints

Yeah, but I dont know how to store a reference in Unreal, I`m new in the engine =/

Thanks

Hey friend, the problem its because in my system, the archer spawns the arrow stopped in it hands then when the archer attack animation finishes, it set the arrow velocity vector.
But sometimes I kill the enemy inside the gap of spawned stopped archer, before the animation attack finishes…

So the final results are: the archer are killed but the stopped arrow starts flying seconds before lol.

yeah but I need to deal with the fact that I have multiple archers, so I need to reference the arrow to a specific archer