HUD reference is always invalid

I’m trying to get information from my HUD class in my character blueprint and make a reference to but it’s always invalid.

Also it’s adding it to the view port even though the reference is invalid, when i take out the IsValid node i get an accessed none error and i don’t know how to get this to work, any solutions?

if you need to hud in your character you should call GetPlayerController and from that GetHud instead. Note: it could be the case that the hud is not created at begin play yet… what is the reason you need the hud in your character? I would advise to do it the other way around (e.g. access the character from the hud)

Thanks for the quick response, i’m trying to change the health of the character when it takes damage in the character blueprint, the health bar is in the HUD because i thought it would be easier to get a reference for the HUD than cast to the individual pieces which i plan on adding.

Unfortunately the GetHud didn’t work and i’m also trying to get this to work for multiplayer and setting the health in the HUD ether wasn’t working or it was changing the health of both clients.

What about creating a dispatcher for the health in the character? Bind the HUD to the change health events and update the health accordingly. Another way is simply getting the health every tick in the HUD and updating it.

I think that’s my main problem the HUD reference isn’t working so i cant access the health bar, it was kinda working before when i had

Event receive damage, get HUD reference, get health bar, get progress bar, get percent and changed it with set percent

But now it’s displaying the HUD and not making the reference work, also this new error just popped up The widget ‘HUD_C’ was already added to the screen. and it came up four times

From what blueprint are you updating/changing the damage from. If its’ from the character bp, then what you have there should work fine. If you are updating from your hud bp, then you need to create a variable for your char in your hud, and set it the same was you did above as the hud reference, but u need to set it before it’s added to the viewport for the reference to update properly. Note, when you go to add the “set” command to the structure you have, before the addtoviewport command, make sure you uncheck the context sensitive in your right click menu so you can access your HUD variables. Then choose the “set whatever_you_call_your_char_variable” from your hud, command and connect the nodes.

Also the reason it’s coming up multiple times is because your executing it via a sequence which is just like a loop and it will continue to execute that sequence during the games ticks unless it’s pushed off the sequence, halting it…

Thanks for the response, yeah the damage is being dealt in the character blueprint and I’ve got a HUD to work like this in other projects which makes it more frustrating.

Also i think the reason the HUD was being added to the view port multiple times was because i had multiple things plugged into the ‘Add to Viewport’ node