Can't set valid values on construct inside UserWidget

Hi all,

I try to set a reference to an C++ defined UActorComponent (“GameplaySystemComponent”) on construction of my user widget.

Basically the GameplaySystemComponent should send a delegate broadcast when an attribute (e.g. Health) updated his value. The given user widget listens to this delegate to update his healthbar.

My issue:

The only way to get a valid reference is when I find my testing Actor (“NewBlueprint”-class) on “Event Construct” and get his GameplaySystemComponent like in the screenshot below.

Every other (preferred) way doesn’t work for me. On “BeginPlay” of my testing Actor i create the widget and set the reference which is marked as “expose on spawn” and right after, I use a “Initialize” function to set the reference manually. Inside this function the reference is valid, but right after it is invalid. Even if I delay the function it doesn’t work.

I also tried with other variable types like Text or float and every time it is the same. I’m also confused by the callstack. As I know “Event Construct” is something like “BeginPlay” for Widgets, but “Initialize” is called before “Event Construct” and even before “Event PreConstruct”.

I hope someone could tell me how to setup a reference the right way.

Have you ever figured out the proper way to do this? We’ve had similar issues with the fact that Construct can fire multiple times if the slate is invalidated (e.g. reparenting the widget to something else) so setting up any kind of runtime logic for said widget will fire again and again in that scenario.

The ugly way to prevent this in our case, given the fact that like you mentioned, we can’t really use the supposed correct(?) OnInitialized as it fires before we get a chance to pass any arguments; is by having a DoOnce node on Construct to make sure it doesn’t fire off again afterwards.