Can't set valid values on construct inside UserWidget
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.
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.
asked Jul 22 '18 at 02:28 PM in Blueprint Scripting
Follow this question
Once you sign in you will be able to subscribe for any updates here