# How to end level after all enemies are destroyed - It end after 1 enemy has been destroyed

**URL:** <https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400>\
**Category:** World Creation\
**Tags:** Destroy, unreal-engine, enemy, UE4, question, Blueprint\
**Created:** [June 29, 2015, 7:44am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400 "2015-06-29T07:44:24Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [June 29, 2015, 7:44am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/1 "2015-06-29T07:44:24Z")

</div>

Currently I am trying to “restart the game” once all 10 enemies on the game have been destroyed.  
But from reading a similar question to solve this I have only become confused.

> **[How to end level after all enemies are destroyed](https://forums.unrealengine.com/questions/199432/how-to-end-level-after-all-enemies-are-destroyed.html)**
>
> I've seen blueprints on ending a level when things are collected or when a single enemy is destroyed, but I can't get either way to work with destroying several of the same enemies in a level. How would I go about scripting this in Blueprints? As a...

At the moment this process works but it restarts once only 1 of the 10 enemies have been destroyed… Any solutions?

 ![48333-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/a/78a354b3cde4947ab511c1ccfdcccd763a9a6e2e.png)

---

<div class="post-metadata">

**Author:** ![PeteX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeteX](https://forums.unrealengine.com/u/PeteX)\
**Post date:** [June 29, 2015, 9:41am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/2 "2015-06-29T09:41:04Z")

</div>

When you get the ReduceEnemyCount event, you are subtracting ten from the Enemy Count variable. That means it will be zero straight away, and the level will end. I imagine you intended to subtract one for each ReduceEnemyCount event, so it would get to zero after that event had been called ten times.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [June 29, 2015, 11:08am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/3 "2015-06-29T11:08:46Z")

</div>

Thanks Pete, I’m still learning my ropes around unreal engine blueprints.  
What you have said is what i’m trying to do.  
Let’s say I have 10 enemies and each time 1 of these actors are destroyed the ReduceEnemyCount will take away 1 from the total amount of points (10)  
How do I do this because i’m still playing with values with no difference, any solutions, or am I missing a big part of this?  
Thank you!

---

<div class="post-metadata">

**Author:** ![PeteX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeteX](https://forums.unrealengine.com/u/PeteX)\
**Post date:** [June 29, 2015, 3:55pm UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/4 "2015-06-29T15:55:50Z")

</div>

Start by looking at the Set Enemy Count node. At its bottom left you have some nodes which give the new value for Enemy Count. Those nodes start with the old value of Enemy Count, and subtract ten from it. This means that you’ll start with Enemy Count set to ten, and then the first time Reduce Enemy Count is called, it will change to zero.

From the bit of blueprint you posted it’s hard to be sure, but you also need to make sure you are setting Enemy Count to ten at the start of the level.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [June 30, 2015, 1:57am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/5 "2015-06-30T01:57:37Z")

</div>

Thank you very much for your patience and time. I understand what you are talking about but with only 1 issue. I believe the game dosnt register the 2nd - 10th enemy as a value, and stops counting down after the first destroyed actor. This is shown when I change the value in the SetEnemyCount Node it counts the death of only 1 actor not the others. I know this may be irritating but if you could help me out it would mean so much! Thank you.alt text

 ![48437-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/e/04e8680fd23c52a2a65016822633af5f615e1ca7.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6199feb8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6199feb8](https://forums.unrealengine.com/u/anonymous_user_6199feb8)\
**Post date:** [June 30, 2015, 5:27am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/6 "2015-06-30T05:27:04Z")

</div>

I dont know if I missunderstand something but where do you store the EnemyCount Variable?  
Just to make sure that its not stored in your BasicEnemy BP.  
And as Pete said, make sure you set the variable because the default value is 0.

---

<div class="post-metadata">

**Author:** ![PeteX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeteX](https://forums.unrealengine.com/u/PeteX)\
**Post date:** [June 30, 2015, 8:53am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/7 "2015-06-30T08:53:43Z")

</div>

If you right-click the Set Enemy Count node, you will have the option of setting a breakpoint. That means execution will stop every time that node is entered. It might be worth trying that, and looking to see for example: whether the node is actually entered for each enemy; what the value is before it is updated; and what the final value is.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [July 1, 2015, 1:12am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/8 "2015-07-01T01:12:01Z")

</div>

Currently all this data such as “SetEnemyCount and ReduceEnemyCount” is stored inside the enemy. I have tried the breakpoint with no result. Unless I’m missing the picture the game dosnt want to count the second death and onward. Preventing me to have a working restart system. If you don’t understand what I mean I can try to make a video making an example of these numbers and show their results.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6199feb8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6199feb8](https://forums.unrealengine.com/u/anonymous_user_6199feb8)\
**Post date:** [July 1, 2015, 3:09am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/9 "2015-07-01T03:09:45Z")

</div>

Well, you should store them in some other place because you destroy the BP and the stored variables 😉

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [July 1, 2015, 4:24am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/10 "2015-07-01T04:24:17Z")

</div>

Sorry still new to unreal and didn’t realize the entire BP would be destroyed after only 1 actor is destroyed. Anything you can tell me of how to store it in another BL, because I made a new BP and it dosnt recognize it within the main actor’s BP.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [July 1, 2015, 4:24am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/11 "2015-07-01T04:24:53Z")

</div>

Also thank you so much for the amazing feedback, was not expecting a ceent and you both have been awesome 😃

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6199feb8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6199feb8](https://forums.unrealengine.com/u/anonymous_user_6199feb8)\
**Post date:** [July 1, 2015, 9:09am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/12 "2015-07-01T09:09:28Z")

</div>

I would store important gamevariables in gamemode or gamestate, depending on what kind of game you are working on.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [July 1, 2015, 9:43am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/13 "2015-07-01T09:43:48Z")

</div>

Ok, so I have now redone this BP inside a GameMode BP, but no difference. Should I be storing these variables somewhere else or is the BP no set up correct? 😕

 ![48626-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/e/95e2786340b847198a63d962f281643c23267854.png)

---

<div class="post-metadata">

**Author:** ![PeteX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeteX](https://forums.unrealengine.com/u/PeteX)\
**Post date:** [July 1, 2015, 10:13am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/14 "2015-07-01T10:13:49Z")

</div>

The Cast to Game Instance node isn’t being used correctly. At the moment I think it probably takes the Cast Failed track each time, which is the reason why nothing happens.

However… If you’re already in the Game Mode blueprint, that’s fine. There is one Game Mode per level, so it’s a perfectly good place to track the enemy count. The thing you mustn’t do is track the count in the enemies’ own blueprints, because those blueprints exist separately for each enemy. When you destroy an enemy, you would destroy the count too.

I wonder if you might have misunderstood this feature of blueprints. Blueprints have logic (the nodes you place with the blueprint editor) and data (variables like the enemy count). When you have a blueprint for an enemy, the logic is shared between all enemies, but the data is private to each individual enemy. The idea is that the enemies can be doing different things based on the data (enemy one is hitting you, enemy two is patrolling) but the logic is the same. The logic needs to be the same, because in other circumstances, enemy two will hit you. You don’t want to have to write the logic for that over and over again, for every enemy.

---

<div class="post-metadata">

**Author:** ![Santeon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Santeon](https://forums.unrealengine.com/u/Santeon)\
**Post date:** [July 1, 2015, 11:26am UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/15 "2015-07-01T11:26:33Z")

</div>

From what you told me I now understand a bit more about actor BP’s and I thank you! For now I need to solve this remaining bit of BP, for I need to figure out how to make the subtraction (BP) activate once the actor has been destroyed. Although I knew how to do it before, it’s a bit more different due to the new BP (GameMode). Thanks

 ![48641-6.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/e/6/de641650d73cf726addf3440047a02610a614b2b.png)

---

<div class="post-metadata">

**Author:** ![Fanto88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fanto88](https://forums.unrealengine.com/u/Fanto88)\
**Post date:** [July 25, 2015, 12:14pm UTC](https://forums.unrealengine.com/t/how-to-end-level-after-all-enemies-are-destroyed-it-end-after-1-enemy-has-been-destroyed/323400/16 "2015-07-25T12:14:25Z")

</div>

Don’t create multiple threads for the same question:

> **[How to end game when all enemies are destroyed?](https://forums.unrealengine.com/questions/263338/how-to-end-game-when-all-enemies-are-destroyed.html)**
>
> Currently I’m trying to end the level once all enemies are destroyed “Cube enemy” and currently the system I have in place is on a Game Mode Blueprint, and I think my largest issue is not knowing how to make this blueprint register a destroyed enemy....
