I have a pretty simple scheme with a widget that is supposed to show the health bar from the enemy. While it seems straight-forward, its not working and I don’t know why. I’m attaching pics of what I have in terms of BP. Just to be clear, I can see the life-bar and its going exactly where I want, the problem is that its value is currently at 0 instead of 100%. And yes I’ve check the life that the monster has, it has 100, I’ve tried taking the life down and that part is working, just the progress bar itself isn’t.
First of all, I’m not quite sure what is going on here.
Your first screenshot looks like you are creating a widget component for your character and then making the widget rotate on tick. If you are just trying to make it always face the player, I believe that you can do the same thing if you just set it to screen space rather than world space (the option should be in the details panel of the node).
Second of all, if you are creating a widget component to attach to your character, it should let you choose which widget to create in the details panel of the node. You shouldn’t also need to use the create widget node before that (you seem to be creating two different versions of the same widget).
If I had to guess why something wasn’t working it would be because perhaps it is showing you one widget but the health value you made is attached to the other widget?
Also, I’m pretty sure the percent bars like that are percent from 1 to 0. I’m not sure what it would think if you actually used a large number like 100. You can have 20/50/100/etc. points of health, of course, but it is only going to understand .2/.5/1 and such when it comes to visually showing the bar.
Thinking about it again, even if you do have two of the same widget, both of the widgets should be responding to the health value if it is bound correctly. One of them can’t “take” it from the other. So the one you are looking at must just not know who its enemy variable is. Try dragging of of the widget component node output and setting yourself as enemy for that one as well.
Also, it might just be because the number you are using is so large. I believe the “normal” way to set the percent when using a binding like that is to divide current health by max health and plug that variable into the binding.
There’s no need to create the widget manually, unless you need some really special mechanics where you replace the widgets run-time, ofc. I believe you’re doing it because you’re not sure how to pass self Enemy reference, you can do it like so:
Amongst other things, the point of the widget component is to maintain the lifecycle of a widget it owns. What you’re doing can potentially bite you. The way garbage collection works with widgets will almost certainly cause a memory leak here.
It was to set a health bar to a spawnable enemy, so every enemy that will spawn will have their own healthbar, which is why I had to create it and pass the “enemy” instance.
This; your widget has a reference to the owning enemy. If it was a traditional 2d widget, you would feed it the refence via an exposed reference variable like you did.
Here, I Set the value of the Enemy variable and point it at the actor who owns this widget component.