Is There a Way to Reset Static Variables Without Re-Compiling?

I currently have a class called GameCharacter which derives from Character. GameCharacter has a static member that holds the amount that are currently in the level. This variable is incremented in the BeginPlay method. The problem is that static members don’t seem to reset when I click Stop. For example, if I click Play with one GameCharacter in my level, the static variable would be 1. When I hit Stop and then Play again, it becomes 2, then 3 etc. The only way to reset the number seems to be to change something in my code, then re-compile. Is there any way to reset this without having to re-compile? Alternatively, if there is a better way to be managing these numbers please tell me. I’m pretty new to the engine and any input is appreciated.

My assumption is that you are Playing In Editor (PIE) mode. Otherwise every time you shutdown the game the static values should reset. There are certain things in PIE mode that carry through unless you completely shut down the editor. My suggestion is run your game a few times, then completely shutdown the editor, then run it again and see if your static values have reset.

If it is not resetting then I would suggest that this is a bug in how statics are handed in the editor. However if it does reset I suggest performing a bit of cleanup. Override the EndPlay function which is called when an actor is removed from the world and decrements your static value.

Actor::EndPlay(EndPlayReason)

The EndPlayReason enum that is passed in actually has a specific value for “EndPlayInEditor” you could use to specifically test for if you only want to perform the cleanup action in PIE.

As you said, PIE seems to be the only time the static values carry over, while launching as standalone does not. Re-launching the editor does reset them as well, but it was just getting annoying having to do either that or re-compile every time I wanted to test something. Cleaning up with EndPlay was exactly what I needed, thanks for the help! Guess I should really look though the game framework more thoroughly!