Health bar not working with other parts of the game


While working on the UI, I was tasked with setting up the Health Bar to enable player vulnerability, essentially allowing them to sustain damage and potentially lose the game. Despite ensuring all setups were correctly implemented, the Health Bar failed to visually represent damage taken. This issue persisted even though debuggers within the code confirmed that damage was registered, and visual feedback (the player character flashing upon taking damage) was functioning correctly. This inconsistency would inevitably lead to player confusion, as they would be unable to gauge their remaining health after sustaining hits. Moreover, the player character would never reach a 'lose' state since the Health Bar did not accurately deplete to zero, rendering them practically immortal.

The issue stemmed from two main causes: 1) The IDamage interface was mistakenly placed in the incorrect code file. Although the implications of this misplacement were initially unclear, it was a deviation from the expected structure. 2) There were duplicate IDamage interfaces: one in PlayerController and another in HealthBar. I initially assumed this redundancy would not lead to any significant problems; however, this assumption proved to be incorrect.

To address this issue, I dedicated approximately two hours to adding debug statements, conducting research, and reworking the code entirely. The breakthrough came when I investigated the mechanism behind the damage flash functionality, which was operating as intended, unlike my IDamage implementation. This investigation revealed an existing IDamage implementation in the PlayerController, which was already set up and functional. The resolution was straightforward from that point: I replaced the temporary placeholders with the newly refined IDamage components. Consequently, the code began to function correctly. With this fix, players can now: 1) Take damage, 2) Die and lose the game, and 3) Accurately track their HP.

Author: Fraser Paterson 

Posted: 3/22/2024

Get Suits of the Abyss

Leave a comment

Log in with itch.io to leave a comment.