Cast failed - Health

Hi, so you try to display the health of the player and the player character inherits from “TestEnemy” / is a “TestEnemy”, right?

I know what are you trying to say hehe 0 and 1 not working. 0-100 not working.
Its just Always “0”
If i connect (for text block) cast failed to return node its shows 0 Like its current health 0

Hello everyone,
From this image this all looks fine but in real… its not like that at all…

WITHOUT BINDING… Text block and progress bar are on screen while playing… (Fill percent works fine )

WITH BINDING … Text block gone progress bar is grey…
Print string on my cast failed works it prints “Hello” hehe

All this binding and scripting works fine on beginning of my game but somehow its just wont work now… I watched so many tutorials about how to set up this simple “code” but its not working Can you try help me
Thanks

Yes, i want to display enemy health bar over enemy grad. But its not showing while i Bind get percent

Just checking, the health is between 0 and 1?

i want to display enemy health bar
over enemy grad.

The logic above will only work if you want to display the health bar of the player, it will not work for anything else. If you want to display the health bar of something else, you will need a reference of that something else (e. g. a reference to that enemy) and then use that instead of “GetPlayerCharacter”, since “GetPlayerCharacter” will return a reference to the character that is currently possessed by the player.

I ll try to do that and will let you know is it working like that :slight_smile:

325253-

This is a result of getting reference to my “TestEnemy”
… Still got a error… I followed this tutorial: Show Health (Progress Bar) Above Widget | Floating Widget - Unreal Engine 4 Tutorial - YouTube

1st time before few months with this tutorial this works fine… Now after i create some game it just wont work… :confused:

Okey i got it boys: this is great now :slight_smile: ill let you know step by step how to do it. CHRUDIMER was right:

  1. Create your char
  2. Add Variable (Float) “Health”)
  3. Create widget and add progress bar ( as you want create it)
  4. In progress bar on PERCENT create Binding (usually "Get Percent 0)
  5. In widget of Health_Widget go to Event graph. Expand from Event Construct > Get all actor of class(Set Actor class as your char you want to show Health on )
  6. Expand Get all actor of class to CAST TO “YourCharachter” (is char you want to show Health )
  7. Out of Actor expand to Get a copy and connect to Object
  8. On Cast to “YourCharachter” ( go right click on As “YourCharachter” and promote it to variable
  9. You ll get your Reference here. Call it as you like
  10. On “Get percent 0” connect it with return node (By default its already connected)
  11. Get your reference ( you call it somehow on step 8 )
  12. expand it to Get (your variable ) Health expand it to float “/” float and / by 100
  13. Connect it with Return value under Return Node

Do not forget to use Widget on your character

This will only work when there is one enemy. Instead you should have the “Test Enemy” class spawn the widget and assign itself (self) to that widget. On the “Test Enemy REF” check the boxes “Instance editable” and “Expose on spawn” then you can assign this variable while you call “Create Widget”

Great, i did it :slight_smile: You can remove Cast to “YourChar” after createing variable from it :slight_smile: then i can multiple enemy in game.
I do it the same way on another char and now its not working with same parameters :smiley: but print string print me Right value… but binded text block is always full hp on Event Any damage :smiley: Grrr

Hey friend i wanted to let you know you are a genius i was not able to solve this health bar problem for nearly a month . Thanks to you soo much