Hi all,
I am trying to wrap my faily complex UI in a UWidgetComponent.
I created a class inheriting from UUserWidget:
Yag3DWidget.h:
public:
UYag3DWidget(const FObjectInitializer& ObjectInitializer);
void SetContent(TSharedRef<SWidget> InContent);
bool CheckMyWidget();
protected:
virtual TSharedRef<SWidget> RebuildWidget() override;
};
---------------------------------------------------------------------------------
Yag3DWidget.cpp:
void UYag3DWidget::SetContent(TSharedRef<SWidget> InContent) { MyWidget = InContent; }
bool UYag3DWidget::CheckMyWidget() { return MyWidget.IsValid(); }
TSharedRef<SWidget> UYag3DWidget::RebuildWidget() { return MyWidget.Pin().ToSharedRef(); }
Then I define the object in the constructor, with a widget component:
This3DWidget = ObjectInitializer.CreateDefaultSubobject<UYag3DWidget>(this, TEXT("3D widget"));
ThisWidgetComponent = ObjectInitializer.CreateDefaultSubobject<UWidgetComponent>(this, TEXT("widget component"));
But with that code, as soon as i call the UWidgetComponent::SetWidget, i get a crash:
This3DWidget->SetContent(YagHUD->YagHUDWidget.ToSharedRef());
if (This3DWidget->CheckMyWidget()) ThisWidgetComponent->SetWidget(This3DWidget);
Where YagHUDWidget is the widget containing all my UI.
Any idea of what i am doing wrong ?
Cheers
Cedric