When exactly does UMG Widget OnInitialized get called?
I'm struggling to find this information in the documentation.
I have the following code:
I want to be able to ensure that
asked Feb 12 '19 at 08:07 PM in C++ Programming
In 4.21, the static method CreateWidget<>() in UserWidget.h calls the BlueprintImplementableEvent OnInitialized() by calling UUserWidget::Initialize().
The exact "call chain" is (everything in UUserWidget):
CreateWidget() -> CreateWidgetInstance() -> CreateInstanceInternal() -> Initialize() -> NativeOnInitialized() -> OnInitialized()
So no, OnInitialized() should be executed "at the same time" than CreateWidget<>() is called. So the behavior you see seems kind of strange. However, I'm not an expert and just looked through the code, I may not understand everything correctly (for instance I don't know if the BlueprintImplementableEvents are delayed for next frame, which should explain the behavior you got).
Keep in mind, however, that the call to OnInitialized() in Initialize() is guarded by this line:
So depending of the context surrounding your code, it may or may not be called. The Initialize() method is also called by: UUserWidget::PostDuplicate() && UUserWidget::RebuildWidget()
Follow this question
Once you sign in you will be able to subscribe for any updates here