UMG Accessing Actor Components?

I’ve been trying to find a way for my UMG Widget that is added as a component to access other components attached to this player. So for example, I have a “HasHealth” component that maintains information about the current health of this object, and now I am attaching a “Widget” component that has a HealthBar I want displayed. This HealthBar needs to communicate with the HasHealth component to find out what the current health of the object is.

In my opinion, it should be something like this in the HealthBar widget:

“Get Owning Actor” -> “Find Other Widgets of Class: HasHealth” -> “Cast To: HasHealth” -> “Get Current Health” -> Return Health %

I’ve tried so many different combinations and haven’t been able to find one that works.

This is a near-exact wording of the problem I had with this method.

LOL! I noticed when I went back and re-read your problem that this was probably what you were talking about… Seems silly if it’s not possible.

Widgets don’t necessarily have an owning component, if they do, they don’t know about them directly. It’s up to you to pass that information to the widget after it’s constructed so it knows something about an owner actor, or component.

I understand that, however - who owns the component widgets? And whether they have an “owner” in the traditional sense, or not - if they are a widget that is added to an object, you should be able to get a reference to that object either directly or indirectly, right? I just can’t figure out how…

I mean, regardless of whether it’s a widget component, or any another component, there should be an easy way to communicate with other components, especially other components attached to the same object.

I would go this way:

  • You have an actor with a Healthvalue stored.
  • this actor has a widget component
  • this widget component has a Widget inside, which is you HealthWidget
  • Since your actor knows the component he can communicate with the components underlying widget

f.e. inside the Actor EventGraph

OnBeginPlay()->GetWidgetComponent->GetWidget->Call UpdateHealth(inHealthValue);

so your widget provides a public custom function called “UpdateHealth” and has an input of type in32/float or whatever.
You actor can call this function via its WidgetComponent everytime the widget needs to update the HealthBarValue. (BeginPlay, Damage, Recover a.s.o)

cheers

I understand what you’re saying, but that’s not what I’m trying to do. The purpose of this exercise was to create a set of Actor Components that I could drop into any game and use without further modification. So as I stated above, I’d add the HasHealth component to an object (any object, not just the player) and that component would have health, be able to take damage, do something when it’s “dead” (I have all of this working already). I also have a “HealthHUD” component that if I add to a player will display their health bar on their HUD (that’s all you need to do is add these two components to any character and they instantly have health and it’s displayed on their screen, no tweaking or touching the blueprints).

The problem comes in when I want to have a component that you add to an object to display it’s health over it’s head. I haven’t quite figured out a way to have one component add another component to the current object yet (mostly because I can’t get the current object that this component is attached to, which seems silly to me). So instead I went the route of, if you want health displayed above an object - instead of adding my custom component, you add a Widget component to that object and set the widget to my custom widget.

But I can’t find any way of getting my custom widget to talk to my custom “HasHealth” component…

You and I have the same thoughts on this issue. Is there a “Set Owner” node?

Making the game logic modular was my thoughts as well.