So I have created some derived classes from UOverlay, UHorizontalBox.
In these classes I have a function called Setup that takes some arguments and looks like this:
void UMHUDOverlay::Setup(UMInventoryComponent* inventoryComponent)
{
UMInventoryDisplay* hotBarDisplay = NewObject<UMInventoryDisplay>(this);
hotBarDisplay->Setup(inventoryComponent->GetHotBar());
UOverlaySlot* overlaySlot = AddChildToOverlay(hotBarDisplay);
}
I call this function in my PlayerController class (in BeginPlay).
Like this:
void MPlayerController::BeginPlay()
{
test = NewObject<UMHUDOverlay>(this);
test->Setup(Cast<AMCharacter>(GetPawn())->GetInventoryComponent());
GEngine->GameViewport->AddViewportWidgetContent(test->TakeWidget());
//....
}
Am I doing something wrong because when the game starts everything is fine
and then after about 1 minute an exception is thrown. (Also this exception can be different each time is crashes)