Kill AI Number of Times?

Just wanted to pop in and help Thompson out really quick because he/she has the right idea. The purpose of making the kill count variable means that it won’t be fixed at all. You will have to implement your own logic to update the amount of deaths until a level is cleared.

The only issue I see here is holding the kill count in the GameMode. Since you’ve described that you want to change levels it would be best to put the kill count in a GameInstance class that way it remains persistent across levels. You could also write a method to increase the kill count based on what level you’re in.

Thompson gave you a very basic idea to get you going, but you’ll have to work out the rest of the details yourself depending on how you want your game to function.

For what you described you would want to run the exact same logic, but instead of casting to GameMode, cast to a GameInstance/SaveGame/CustomActor class, then instead of quitting the game, open the level that you want to go to next.

If you don’t want to travel to a whole new level, you can increase the kill count variable in your game instance, then call the game modes RestartLevel method to reset the state of your level and carry on from there. You should also have a custom actor that handles how many enemies to spawn based on your kill count variable.

Here’s some screenshots to help you visualize what I’m talking about.

The rest of the code that Thompson posted is valid so I won’t duplicate that, but the only difference is I recommend a GameInstance or SaveGame class to keep the persistent kill count working through multiple levels. If your game is more of a one and done kind of thing (see how many levels you can win in one playthrough) or if you’re using the same level every time then the GameMode should work fine. Though beware that resetting the level resets all actors in that level.

I hope this helps!