Posted September 20, 2025 by JarenU
Preface:
Sometimes it is good to have a bit of foresight when it comes to development. It sucks having to go back and fix things you have already made. But hey, hindsight is 20/20. Up until now many of the data being plugged into the HUD are being stored in the player object, which in most cases is fine. But with our latest feature "Enemy Possession", it becomes a problem. To break it down, this is how the possession system works:
De-possessing an enemy is similar, but in reverse. Where it destroys the possessed enemy and respawns the enemy and player objects.
Problem:
Destroying the player removes all of the variables and data that the HUD and other systems might be needing. Either not allowing them to update, or worst case causing runtime errors. This is most apparent in the player HUD, with some values either being frozen or set to null.
Another issue is what when the player de-possesses an enemy and respawns the player, the begin play events triggers, adding another HUD to the viewport. Causing them to overlap on the screen.
Solution
The fix for the first problem I had to go to where every variable I wanted to persist to be moved from the player, to the game instance. Combing through all of my previous code to find where I have get/set them all. Then also adding anything that needed updating into the possessed enemy code. Such as keeping track of how long the player has been in the level.
To solve the other issue is a simple fix. Whenever the player possesses or de-possesses an enemy, the HUD is removed during that action, to then be added during the begin play for both objects.