How should I bind variables to make a widget work as a HUD for an NPC in worldspac

First off thanks for taking a look. My sanity is on the fritz.

Anyways what I am trying to do is create a health bar type thing that works for NPCs in world space. You can find similar functionality in games like Destiny and Warframe. So far I think my issue is in binding the variables necessary to drive the progress bar and text in the widget.

It looks like when I try to cast to the class that has the widget component it gets all members of the class in the world. I can’t figure out how to get just one actor per instance of the widget. (btw I think I’m using the right terminology sorry if I’m not)

I’ve read the docs, done a lot of tests, watched tutorials… etc but to no avail. It seems like the old method for binding the variables doesn’t work either. As seen … Unreal Engine 4 Tutorial - 3D Health Bar (NPC's) - YouTube.

Hopefully the screenshots I took will make more sense.

^ This is my current setup in the main graph of the HUD BP. I’ve tried a few different methods but this way works the best so far.

^Going but the Print String from the pic above. So far it looks like the For Loop runs through for each actor of the class. So it runs the For Loop 6x. The widget looks the same for every actor even though the blue Print String shows that the variable I’m trying to bind isn’t the same for each actor in the class.

^ So then I tried to see if the widgets start wonky but will work when I interact with the actors. So I set up some simple functionality to adjust the health values while playtesting. This is where things got SUPER confusing. (That screen space trace node is a function I build to do a simple line trace from the center of the screen into the world) I would hit the actors but it would only reduce the targets health once. After that all successive hits did nothing. And the progress bar only went down when I hit the right actor. (the right actor seems random) But when the progress bar went down it affected all of them at once.

So, as you can see, I’m lost. Can I get a pointer or two. Please and thank you.

P.S. Ignore the health, energy, stamina bit. I know the 75/100 is off. That isn’t much trouble I’m just feeling lazy about that part. Those bars work just fine.

So where do you construct those hearth bars?

I can’t get to my computer right now but if memory serves I have the widget in an Active node in the class BP for those spheres.

Hello jaredcfw,

If I understand you correctly you would like to affect your 3D widgets separately? If that is the case you will need to use the “Get User Widget Object” node. I have provided an example below. I hope that this information helps.

Example:

Here I have used an on hit event to decrement the Health value by 0.1.

Make it a great day

Thanks for the help. Unfortunately it didn’t work. Before I saw this I had a similar- setup.

Then after seeing your message I tried making a few changes and ended up with…

I’ve noticed that my interface based event doesn’t get called for all of the actors in the class. So I tried using different events. Even tick didn’t change the values. But At least now each health bar reflects its own value when I start. At least I made some progress.

It sounds like the issue may now lie in when the event is getting called to deal damage. Could you should how exactly it is you are selecting your target and how the damage event is being called? As long as the event in the second image (after modifications) is only being called on one actor then that is the only actor that should be effected. This means that if you are seeing multiple actors being updated when only one should be damaged that the error must be with how the damage event is being called.

That’s what I’m thinking too. Problem is the functionality seems super sporadic. I’m calling the event using the method in the 3rd image I posted above. Basically I press 3 and from the center of the screen I do a line trace out up to 50 meters. Then I use the hit actor as the target for the interface message thingy. I was thinking that that would be the only way to call a specific actor to affect it directly.

Have you tried using a custom event instead of a interface?

Actually no. I was under the impression that custom events were limited to the BP they were made in. But even if that’s true I should still be able to access it since I’m setting all actors involved as a variable. I think… maybe? Anyways I’ll give that a try this evening. Thanks

After some coffee, meditation, and tears I finally figured out why the healthbars failed to properly update after casting to them properly. If you look at the last pic I uploaded you can see some floats doing floaty things. Problem was I would subtract from Current Health but never reset its value. So It wouldn’t update because nothing really changed.

Thank you so much for pointing me in the right direction. Can’t believe my crappy math gave me this headache.

Also now that I think about it I should’ve followed your example more closely. Since I had multiple variables for health I kinda glossed over your math. Thanks again.

I am happy that you were able to resolve your issue. I am going to go ahead and mark this as resolved.

Make it a great day