# 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:** 3

<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 29, 2021, 9:41am 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/41 "2021-12-29T09:41:06Z")

</div>

Good progress.

The spawn position should probably be determined by the spawner itself or set to specific areas.

Basically, before you allow the spawn you check the capsule size with a sweep and test if the object can indeed be spawned where you want it to.  
If it can you proceed, if it cannot, you find another spot.

Further development of that would obviously tie into either nav mesh or nav invokers. However it’s likely overkill for your needs.

Keep it simple. Have some components into the level as spawners.  
Make the master spawner look up all the elements of that type and select a random number in the range of 1 to the array count.

Then take that transform in world as the spawn transform.

Beware that the spawn transform may be Local and not World aligned - I can’t recall how it solves.  
If it’s local, then you need to do math (subtract The spawner BP location? Or just run a transform from world to local on the spawn spot world location which is easier).

---

<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 29, 2021, 2:33pm 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/42 "2021-12-29T14:33:25Z")

</div>

Could you show it in the UE4 editor? Like with screenshots and stuff, I’m not really familiar with spawning and stuff.

---

<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 29, 2021, 10:57pm 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/43 "2021-12-29T22:57:44Z")

</div>

I don’t have anything I can show (nda prevent it).  
If you can be more specific on what part confuses you, maybe I can recreate it and share how it was done.

---

<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 30, 2021, 3: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/44 "2021-12-30T03:25:22Z")

</div>

> [@post:41](#):
>
> before you allow the spawn you check the capsule size with a sweep and test if the object can indeed be spawned where you want it to.  
> If it can you proceed, if it cannot, you find another spot.

> [@post:41](#):
>
> Make the master spawner look up all the elements of that type and select a random number in the range of 1 to the array count.

How do I do this ^

---

<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 30, 2021, 10:43am 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/45 "2021-12-30T10:43:04Z")

</div>

Ok,  
I’ll do some stuff tomorrow.

Meanwhile.

To check if the spawn area is free you can do a capsule trace that matches the size of the capsule of the character and the position its in.  
Assuming it gets no hits, you are clear to Spawn.

To gather objects and randomly select one for the location, you would use gameplay tags.  
Because you can look them up, and get an array of objects to work with, they are particularly good for this use case in a smaller sized project.

---

<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 30, 2021, 11:15am 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/46 "2021-12-30T11:15:55Z")

</div>

Okay thanks 🙂

---

<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 31, 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/47 "2021-12-31T07:32:46Z")

</div>

I hope you will show it today 🥺

---

<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 31, 2021, 9:30am 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/48 "2021-12-31T09:30:49Z")

</div>

![SpawnBP](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/1/617b6657e979617479ad728ffb8ce78ea5725d88.jpeg)

Short video is uploading

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/f/affe5b0d1d1f850ff90e082cf931fe5f45fa0819.jpeg "Random Not Random Spawn") ](https://www.youtube.com/watch?v=NR6-ufcwONw)

---

<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 31, 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/49 "2021-12-31T09:53:20Z")

</div>

Thank you so much for sending it, I think this is gonna be the solution : )

---

<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 31, 2021, 9:56am 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/50 "2021-12-31T09:56:46Z")

</div>

Make sure you don’t spawn on tick. That’s really just for testing purposes, as I didn’t want to click the bluetility button of the BP to manually spawn things while filming.

---

<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 31, 2021, 1:09pm 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/51 "2021-12-31T13:09:33Z")

</div>

Ok

---

<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 31, 2021, 1:47pm 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/52 "2021-12-31T13:47:07Z")

</div>

How do you do this?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/8/f87f3d68a980156c5f05959dede99d4021172a9e.png)

For me it’s coming like this.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/0/80eddf924cc59a8c91ef5e544baca1b89d537d94.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 31, 2021, 1:52pm 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/53 "2021-12-31T13:52:54Z")

</div>

How do you do this too?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/8/7806298f8e43c013b083d5f66521aa3873681881.png)

For me it’s coming like this.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/b/0bfd4449fd4463300ec6aa769cd9ef57c8ab8c15.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 31, 2021, 6:38pm 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/54 "2021-12-31T18:38:31Z")

</div>

Right click the pins and select split pins. I think that is the name I’m not at my computer so I can’t confirm.

---

<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:** [January 2, 2022, 7: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/55 "2022-01-02T07:13:28Z")

</div>

I’m facing this error.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/c/fcfcfb8ad38105a82591a2aae75dee70931ca267.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:** [January 2, 2022, 7:42am 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/56 "2022-01-02T07:42:23Z")

</div>

You probably forgot to expose it and set it.

It doesn’t need to be an actor variable either, be creative. It can be pretty much anything from an array of soft references to an array of classes, to (as I was using it), a reference to an existing level item.

---

<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:** [January 2, 2022, 8:27am 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/57 "2022-01-02T08:27:49Z")

</div>

Ok

---

<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:** [January 2, 2022, 11:49am 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/58 "2022-01-02T11:49:07Z")

</div>

A Spawn What? variable is this.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/3/832861eecde2e501674e3d017fb44651ac46222c.png)

What is it that I am doing wrong?

---

<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:** [January 2, 2022, 12:00pm 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/59 "2022-01-02T12:00:49Z")

</div>

@MostHost_LA I’m sending you some references so that it will be easier for you to solve the problem : )

> Spawn Enemy Event:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/2/42578538ee1808498c5f75c225cf81933eabe220.png)

> Aa Spawn Spots:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/9/09e9673fd566c85d70fd03d86bea1d23aaf781b2.png)

> A Current Spawn:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/2/924ec898bb9e7a4bb4e540bff74d9319acc1098b.png)

> V Spawn Loc:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/9/a9590c52520d72b1b13be6ef7911ba810e6417bc.png)

> A Spawn What?
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/d/0d69e69078ed72fc26a21d89449a6123b058f419.png)

> F Spawn Counter:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/1/21ac69a6b333b5168a7ae6cba954f06b7a4ee801.png)

> F Spawn Interval:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/0/50178483369a784fe3bb8a703d3c3b3193ea9d0f.png)

Also I can’t add the places to spawn in the array because of this.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/b/1bc754b1edbe9e57d70c98a9b46c1f858034f106.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:** [January 2, 2022, 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/60 "2022-01-02T14:02:25Z")

</div>

Expose on spawn, then select what it is in the level editor.

[Previous 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)

[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=4)
