How do I cast to a specific object in the world from inside an UI element?

So I have an actor blueprint in the world that is a building with ‘hit points’. The hit points are decreased as another character that moves around the level touches this building.

That all works great, and each individual building in the world will take individual damage as the damaging character moves around. But I have a health bar (a progress bar ui element) on top of the building, this health bar has the following ‘get percent’ function. To be specific, this health bar is a widget added in the building’s blueprint.

So, none of these work. In A, the cast fails as the object input is most likely wrong, in the example it’s set to be just a reference to “Actor”. How could I make this input reference a unique object in the level?

In B, it “works”, but it affects every building’s health bar, even though the values themselves do remain unique to each building. So basically when the damaging character touches the 2nd building, the health bar doesn’t decrease. It will only decrease when it damages the first building.

In C, I tried to get a copy from an array but it’s exactly the same result as B.

1 Like

Rather than going this way ( widget searches for thing ), it might be an idea to get the building to create it’s own widget.

That way, it can just tell the widget when to update. No confusion about which building has which widget.

2 Likes

I originally gave this a shot and was a bit stumped. So trying again this morning and ran into a similar issue…

The ‘create widget’ function doesn’t allow me to place the widget inside the blueprint, so my question is it will put them in ‘player space’? And not sure exactly what to plug into ‘owning player’ as ‘get player pawn’ or ‘get player character’ don’t work there. I can extract the ‘get percent’ value from there, but otherwise I don’t know how to make this function.

The other option, ‘add widget component’ does allow me to physically see the widget added to the building when I play, but I am not able to extract the ‘get percent’ function from the node, basically it doesn’t open up the option to edit the widget itself. So I know I’m missing something here and if you know I’d appreciate the tip!

1 Like

Yes, widget component, you’re on the right track

You can talk to the widget with an interface. In the building

In the widget

widg

2 Likes

Wow, thank you so much for that! Couldn’t have made it clearer. :folded_hands:

1 Like

You’re welcome :star_struck: