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

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.

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

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.

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!

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.

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

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.

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.

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.

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

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.

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

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

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? :confused:

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.

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

Don’t create multiple threads for the same question: