How to use UWidgetComponent::SetWidget?

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

I have created a thread on the forum:

I will post a solution on both sites when i get one.

Cheers

Cedric

I found a solution and posted it here:

Only problem left is that the widget is responsive to mouse only on the server and not on clients, but that’s another problem.

Hope this helps

Cheers

Cedric