Where is it better to put death logic?

HI! I have a component responsible for the health of the player/enemy, and I have a question: where is the best place to put the death logic?
I have two options:

  1. Either leave it in the component itself;
  2. Create an event dispatcher that will be called when the HP reaches 0, bind this event dispatcher to the player/enemy, and put the death logic there.

Hey @blAddddDe!

I would say it’s best to keep it in the component, then check on what controller is attached to the pawn (if you’re using the same pawn for both player and enemies) and do branching logic based on if it’s a player vs enemy. For instance, enemy maybe adds points to score before dying, player has a UI menu open saying “you died” etc.

Try to put as much on components as you can, so there isn’t as much to load per character. It’d be even better if you had “BPC_Health”, “BPC_Player”, “BPC_Enemy” so you can just determine when they spawn what they’ll need.

Then whatever controller is attached, have it add that type of component to the actor.
The BPC_Health could then “Get Component” with the actor plugged in, try BPC_player then if it returns nothing try BPC_Enemy, then for each of those have an event or function tied to death you can call.

Hope that helps!

1 Like

I have it in my Player State where Health is managed.

Damage is sent to the player state to be deducted from “Health”.
After deduction, clamping Min: 0.00 and Max: Max Health, Check if Health is == 0.00.
If so, I set bIsAlive to False and call an event in the GM to record the death, update game stats and call down to the server proxy to Kill the player (disable movement, ragdoll etc), then unposses the pawn.