Handling local multi-player Co-op hud and health systems

Hi I’m wondering if anyone could share some insight into a problem I’m having with figuring out my health systems. Currently I’m working on a project that involves 2-4 players spawning into a map with their own screens and health, inventory etc.
I’ve been editing the ThirdPersonBP but for my 4 characters I created 4 children of that blueprint (with a player index variable to help identify each player) and have the levelbp spawn them.

So far I’ve been able to figure out how to give each of them an Individual HUD of sorts that displays their health bar. I’m currently facing issues understanding how to damage each player individually and reflect that in their UI. It seems to be working kind of, I have a pain causing volume in the level and when player 1 goes into it it ticks them like it should, however when player 2 does, it instantly drops to 0.
I’m also noticing that while player 1s health is being reset to 100 when I start the game, player 2 is not and I’m believing that these two issues are connected. Any insight or tutorial that you could point me to would be very helpful.

I would attach screenshots but I’m currently not at my workstation and wanted to get this post up.

Thanks in advance!

Here is an image of my controller blueprint that gets attached to each player when they are spawned. I believe they each get an instance of this

This one is my HUD blueprint. I did think to set the health here in the construct once the HUD is created but for some reason this made it so that player 1s health drops to 0 as soon as they take any damage.

This node is called on BeginPlay from the ThirdPersonBP Parent to start the players health at 100, however it doesn’t set player 2 to 100, they just stay at 75 which is my test health to make sure the values are changing.

I believe this is the last node related to setting health, this one also exists in the ThirdPersonBP Parent and just is taking note of the damage taken. I also believe this is not correct. I was thinking I could take the any damage event and have it only apply to the player controller of the player index that is taking damage but this seemingly didn’t do anything.

im a bit confused by your logic,

why not just do damage to the pawn rather than pass it to the controller?

but yeah it sounds like maxhealth isnt begin set on player2, where do you set it, does it have a default value?

easy way to test where its failing is using breakpoints and print strings on the value

Well I was following a tutorial and I was just following how they had set it up, so I wasn’t 100% sure why they were doing what they were doing. Are you saying instead of calling a function from the HUD in the controller class after calling the controller function in the thirdpersonBP, I could just call the HUD function in the thirdpersonBP?

I’m currently setting the current health to MaxHealth which is a value of 100 on BeginPlay in the ThirdPersonBP.

i mean i guess anywhere works but just makes sense to damage the pawn if the pawn is being damaged :wink:

so with the health add a few print strings and insure its being set on player 2

I suspect your variables and nodes dealing with PlayerIndex are simply wrong.

You don’t need them.

image

You are in PlayerController’s BeginPlay, grabbing your own index so you can get your own playercontroller by index ? That sounds redundant. Just use Self.

Same for character BP. You have a PlayerIndex variable, and getting character or controller by index, when you could directly use Self or GetController.

image

So what ended up working for me here was passing the damage from EventAnyDamage in the PlayerBP to a variable in a function from the controller blueprint. In that function I do my damage calculation which actually does what it should and then updates the HUD. With this now all my characters health goes down individually and I was even able to have my projectile apply damage on impact.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.