Can I pass variables to a widget component and how?

To access the widget:

In this Widget I have the health bar and i want to set percent with the event tick of the Widget Blueprint.

It’s not a great approach. Consider telling the widget what to do, rather than having it pull data out of other objects. UI should display what you tell it to, not search for data.


If you must do it this way (hey, it’s your project!), create a variable of BP_NPC type inside the widget and SET it on the BP_NPC’s Begin Play using the nodes above. Also, since you’re going to use Tick anyway, you might as well use property binding - it’s polled every frame:

  • in the widget, create a reference variable:

image

The above assumes Health is in 0-1 range already.

  • in the NPC:

It’s not that bad tbh, and should work well in some scenarios despite being very tightly coupled.