# How to play Death Animation whenever the enemies Health is 0? (In Blueprints or C++ and spawn again with the AI Controller)

**URL:** <https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910>\
**Category:** Character & Animation\
**Tags:** unreal-engine, Blueprint, UE4-27, question\
**Created:** [December 23, 2021, 5:21am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910 "2021-12-23T05:21:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 23, 2021, 5:21am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/1 "2021-12-23T05:21:44Z")

</div>

Please just guide me how can I do this 🥺

---

<div class="post-metadata">

**Author:** ![SunbeamOut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SunbeamOut](https://forums.unrealengine.com/u/SunbeamOut)\
**Post date:** [December 23, 2021, 11:32am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/2 "2021-12-23T11:32:47Z")

</div>

When you know that your character is dead there are your options :

1. Just turn on ragdoll physics and it will fall by itself. Also, add some small force so it will fall in the right direction.
2. Play certain animation via AnimMontage and make sure that characters stay at this pose or enable ragdoll afterward.

To track down when Health \<= 0 you should add damage via some function that will check health amount after applying damage.

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 23, 2021, 12:31pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/3 "2021-12-23T12:31:29Z")

</div>

To play the montage, add an animation slot between the state machine and the pose (in the animation blueprint).  
Then you can use Play Montage from blueprint (or c++). This node as a “animation completed” pin that you can use to remove the pawn after he’s dead or add some kind of effect.

Edit:  
To play from C++ and use the montage callbacks, search for this class in the Visual Studio solution:  
UPlayMontageCallbackProxy. You can base your code from there.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [December 24, 2021, 1:16am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/4 "2021-12-24T01:16:01Z")

</div>

To prevent bugs:  
Create a statemachine called “dead” in the animation.  
Whenever the character is actually dead (so after ragdoll or animation plays out) toss the animation in this state.  
Usually with a pose snapshot so it costs near nothing.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 24, 2021, 3:59am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/5 "2021-12-24T03:59:04Z")

</div>

So basically the problem is that I already have a idle and running animation attached to the enemies mesh, and I can’t put another so the death animation isn’t really working.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/a/aa2591fc1d0bf9b8a58b65f9f8d19dd33ec907c5.png)  
(this is the screenshot of the death animation blueprint ^)

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [December 24, 2021, 9:16am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/6 "2021-12-24T09:16:13Z")

</div>

That makes 0 sense.  
You aren’t limited to anything - there’s no reason you can’t just add another state and transition to it.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 24, 2021, 9:53am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/7 "2021-12-24T09:53:39Z")

</div>

Okay sorry forget that stupid thing I said, can you tell me how do I switch states?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/d/dd15b2d9c45b76dc070b44dbaca5dd01896cb7e5.png)

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [December 24, 2021, 10:48am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/8 "2021-12-24T10:48:55Z")

</div>

There’s a learn tab on the epic website.

You should access it and look for animation tutorials.

It will teach you how it works and the basics you need to know to use the engine.

Also this series.  
https://www.youtube.com/embed/videoseries?list=PLfQ3pODBwOcaV1TdnqNWLTJ4wiUzEvXis&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 24, 2021, 11:25am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/9 "2021-12-24T11:25:09Z")

</div>

MostHost\_LA is absolutely right. You can’t post a question every time you have a problem. Make some search first. I’ve never used double state machines but possibly I know how to do that. You have to cache the poses that come out from the state machine. How do I know that? Because I’ve watched countless videos about animation. Have you completed the courses from the Unreal Learning Portal? That’s a good place to start.

But you don’t need multiple state machines for the death animation. It’s a lot simple to play a montage when the vampire dies.

You just have to add a animation slot between the state machine and the Output Pose. If a montage is playing on that slot, it will override de animation that comes out from the state machine.

You can play the montage from your blueprint with Play Montage.  
[Unreal Engine 4 - Animation Montage Setup - YouTube](https://www.youtube.com/watch?v=NU__D2EXhkY)

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 24, 2021, 6:18pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/10 "2021-12-24T18:18:35Z")

</div>

@SunbeamOut @Limanima @MostHost_LA Okay sorry for just disturbing you guys with my silly questions 😔

> 1. I created a Dead State in the BP\_Enemy\_Animation Blueprint  
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/5/c5cb8fc42573654ea4e6a2921ce9b423e2f0a71b.png)
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/8/f89e5264615f44981bfc1f362b93b1f3fa551a64.png)

> 1. Transition from Idle/Walk to Dead State.  
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/b/2b1417c134c12e0cb2cba22afc327cfff429b22f.png)

> 1. Changed the Tick Event in BP\_Enemy.  
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/c/2cc62fa1af2ce130ab6b0d2ac73ef362fa78ada3.png)

> 1. Changed the BeginPlay Event in BP\_Enemy.  
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/0/004efb2b65b920c4628356ecd1d82c14ef3b59ce.png)

> 1. Commented this part of my Enemy.cpp file so that it doesn’t interfere.  
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/8/2892c7304db5935863053090a468fcd20eb5ea34.png)

> References: YouTube tutorial I followed: [https://youtu.be/naBMp4EqujM](https://youtu.be/naBMp4EqujM)

**But the problem I’m facing now is: Enemy is not dying or playing the animation and not getting destroyed.**

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 25, 2021, 7:32am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/11 "2021-12-25T07:32:11Z")

</div>

@MostHost_LA @Limanima @SunbeamOut Please reply!!! I’ve Been waiting for almost forever. Merry Christmas btw 🙂

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 25, 2021, 8:39am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/12 "2021-12-25T08:39:50Z")

</div>

The only thing I didn’t see in your code is the damage being dealt. Where do you change Enemy health?

---

<div class="post-metadata">

**Author:** ![SunbeamOut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SunbeamOut](https://forums.unrealengine.com/u/SunbeamOut)\
**Post date:** [December 25, 2021, 11:13am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/13 "2021-12-25T11:13:56Z")

</div>

You need to try to resolve errors on your own.  
Where do you set up IsDead variable and deal damage? Check this two points

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 25, 2021, 1:17pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/14 "2021-12-25T13:17:46Z")

</div>

In the Enemy.cpp file.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/e/6e08402fa98d7f4a89c4ec061a81e516bff9bf7a.png)

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 25, 2021, 1:19pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/15 "2021-12-25T13:19:31Z")

</div>

In the BP\_Enemy\_Animation.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/c/2c5746cdb7a18aea44b29b8f3c39d88c5141c242.png)

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 25, 2021, 6:41pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/16 "2021-12-25T18:41:44Z")

</div>

When is AEnemy::DealDamaga() called? Is “Health” in C++ the same variable as “Enemy Health” in Blueprint?

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 26, 2021, 6:18pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/17 "2021-12-26T18:18:29Z")

</div>

Okay thanks I figured everything out. The animation is playing properly, the enemy gets destroyed after that. But now can you tell me how to respawn the enemy after he dies? Checked the UE4 documentation, couldn’t find anything helpful.

> I call the Spawn Enemy Event after the Destroy Actor function is called, but then when I hit play the Game crashes after 3-4 seconds or so.
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/c/4cd7897dc68e0a23b558b8d636858d660e66a829.png)

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 27, 2021, 6:55am UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/18 "2021-12-27T06:55:07Z")

</div>

Okay now the Game is not crashing cause I added a Delay after Destroy Actor and then called the Spawn Enemy.

> But now the problem is that they are not spawned in the map, they are spawned in the world. So they are not visible, what should I do now?

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 27, 2021, 2:02pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/19 "2021-12-27T14:02:59Z")

</div>

@Limanima Hey it’s been long since you replied to this post.

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 27, 2021, 3:40pm UTC](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910/20 "2021-12-27T15:40:14Z")

</div>

Sorry.  
First, if you are respanwing the enemy after he’s dead, why are you destroying him in the first place if you are going to revive him?  
Just respawn him, I don’t see the need to destroy the actor.

Second, where do you want to respawn the enemy? You are using “GetActorTransform”, I’m not sure what will this return if you have destroyed the actor. Maybe someone on the forum knows what happens.

You have to tell somewhere the respawn location. Maybe you will have to add respawn points, because if it’s random you will never know where it will respawn, on top of a wall for instance.

[Next page](https://forums.unrealengine.com/t/how-to-play-death-animation-whenever-the-enemies-health-is-0-in-blueprints-or-c-and-spawn-again-with-the-ai-controller/267910.md?page=2)
