UUserWidget Initialize vs NativeConstruct

What are the differences between those two, and when should I override each?
Both seem to be called only once per construction.

void UMyWidget::NativeConstruct () {
  Super::NativeConstruct();
}
bool UMyWidget::Initialize () {
  if (!Super::Initialize()) return false;
  return true;
}

I’ve checked the source code. To me, it looks like Initialize() handles a lot of internal stuff, so you aren’t meant to override it directly I think. The Native events are what you should override instead.

virtual void NativeOnInitialized();
virtual void NativePreConstruct();
virtual void NativeConstruct();
virtual void NativeDestruct();
2 Likes

Thanks. If I may push for more info if you’d know or know where to look, what’s the difference between those? That it goes up along the list is obvious, and when is Destruct called is also obvious.

Construct is just before adding the widget to viewport, called each time added to viewport it seems to me from logging. But how’s that different from other two is lost on me.

Was looking for some lifecycle diagram like for Actors, but couldn’t find any. Much appreciated.

I don’t know the exact order unfortunately, but you can step into any function in Visual Studio and see what happens at every stage.

1 Like

NativeOnInitialized is called when you create the widget

NativePreConstruct is called when the widget is added to a viewport and when viewing the widget in the editor

NativeConstruct is called when the widget is added to a viewport, after NativePreConstruct

NativeDestruct is called when the widget is removed from a viewport

3 Likes