I am trying to get UE4 to count the number of enemies killed in my unlimited wave spawned game before spawning in a new type of enemy. What are some tricks or guides you know? Maybe something that I can read more up on?
One way would be having an int in your player state or character and every time the actor is killed you can cast to the player state or character and add 1 to the variable, then just put this in a widget and show it on screen. I would only use your character class as a temporary solution i normally but all variables like: kills, deaths etc. in my player state.
I have never tried this before so it might not work but i dont see why it wouldn’t, On begin play you can check if there are any enemies spawned (Get all actors of class, then get the length of it and if its equal to 0 then use a function to spawn the enemies) If enemies are spawned when one is killed you want to destroy to enemy and then do the check again and it will keep doing this on every kill and when it is time to spawn another wave then it will do that.
I would probably do something similar like rapiidzz901 suggested, the only thing I would do slightly different is storing the integer count in the GameState object instead of the PlayerState, this will keep things more controlled and on a more ‘game level’ type height. This will also help you in cases if you ever try to have multiple people in your game as well (and even architect to have different types of kill counts) and still works fine in single player. Hope that helps!
Either way will work, just depends on your preference and what you want to do with your game systems.
Update: Thanks for the help everyone. I created the variable in the blueprint game mode and updated that variable right before each enemy is killed in the blueprint enemy base. Now i just need to figure out how to swith the enemy type after so many kills and i should be about complete.
Off the top of my head one way it could be done is by using an enum. Inside the enum have your enemy types. Where you spawn the enemy do a switch on Enum name and for each option do spawn actor from class. So when you hit a certain amount of kills set the enum to a new type and the switch will do the rest.
I don’t have to worry about that now. I got it all figured out and this is how I did it. Let me know if you cant see it and I will break it down for you guys.