My problem occurs when I use the “NewObject” function to create my custom Widget, that is derived from UUserWidget.
Inside my custom class I have an UButton that I initialize in “OnWidgetRebuilt”. But that UButton remains nullptr after I create my widget with “NewObject”. Probably because “OnWidgetRebuilt” does not get called.
My question is as follows:
What virtual function should I override in my “custom widget” class, so that when I create a “custom widget” the overriden function is called. (And I can initialize other Widgets in that function).
This is where my UButton get initialized:
void UMInventorySlot::OnWidgetRebuilt()
{
slotButton = Cast<UButton>(WidgetTree->RootWidget = WidgetTree->ConstructWidget<UButton>(UButton::StaticClass(), FName("inventorySlot")));
// Delegates
slotButton->OnPressed.AddDynamic(this, &UMInventorySlot::OnPressedEnterDel);
slotButton->OnReleased.AddDynamic(this, &UMInventorySlot::OnPressedExitDel);
slotButton->OnHovered.AddDynamic(this, &UMInventorySlot::OnHoverEnterDel);
slotButton->OnUnhovered.AddDynamic(this, &UMInventorySlot::OnHoverExitDel);
// ~Delegates
Super::OnWidgetRebuilt();
}