In this video, this guy is building a floating healthbar above both player and AI characters. I have followed along and successfully got the healthbar working for an AI character I’ve created, but when trying to apply the exact same process to my playable character, the BP I’ve built cant get the health of the character and the code fails with error:
Blueprint Runtime Error: “Accessed None trying to read property HealthInterface”. Node: Get Health as Ratio Graph: GetHealthPercent Function: Get Health Percent Blueprint: BP_HealthBar.
I’m not sure whaats going wrong, but I suspect it has something to do with my playable character being a wheeled vehicle pawn. just not sure what aspect of that is causing the issue.
What’s happening, is when I attempt to cast the playable pawn to BP_HealthInterface, the cast fails and the healthbar above my playable character never shows the health.
I’d love some pointers about how to fix this, as I don’t know enough to know how to fix this or where to look to start diagnosing what’s wrong.
Thanks for your time!
I would suspect the object reference in your cast using “self” would be a culprit if the pawn did in fact have implement the interface in question…
Seeing that seems where it’s accessing “none” I feel like it needs to use one of the built in functions such as “GetUserWidget” as the object reference or something along those lines.
In your character/pawn blueprint go to class settings and in the details window is should show “Implemented Interfaces”. I’m not using UE5 at the moment, but it should be similar.
If its not listed there you can add it there. It should also be showing under the “Interfaces” category in the “My Blueprint” window where all your variables are showing. Again I’m not sure if this is exactly the same in UE5, but it should be close.
This did it for me. No longer getting the error message. Thank you. I had forgotten to add the health interface in the interface implementation. Strangely enough still not getting the actual health to show up on the bar though…the exact same BP works on my AI character, just not the player pawn… Any idea why something like that might happen?
Have you also checked that the variable is connected in the actual interface of the pawn? You may need to be casting to that pawn to do so and it might be failing there… for instance if you’re using Hud States it may be returning an empty variable.
Not 100% sure what you mean, still very new to blueprints. Which variable, what interface?
I know through testing that when I use the ‘GetHealthAsRatio’ function on my playable character, it returns 0 where as on my AI character it returns 1.0. So its definitely not grabbing the health variable on my playable character, just a matter of figuring out why
I can’t say for sure as to what implementation you got your AI character to show the health, but if you retrace your steps to what you did there, you’ll probably find a cast to pass the AI character health into the interface and when in possession of the playable character it’s not casting to that character as well because it’s only casting to the AI character. If that’s the case on the failed cast you can cast to your playable character to retrieve the health from that character. If you’re using two different pawn blueprints with the same interface it needs a way to distinguish which one it’s getting the health variable from.