AddToViewport crash ue4 without error message

Hello, Sorry in advance for my English, I do not speak very well.

When I call the AddToViewport method of my class UShopUserWidget : public UMyUserWidget, Unreal Engine 4 crash without error message in the console.

Here is my Code:

In my TheClass.h

<pre>

UPROPERTY()
UMyUserWidget* TheClassWidget;

UPROPERTY(EditAnywhere, Category=Widgets)
TSubclassOf<UMyUserWidget> wTheClassWidget;

</pre>

In my TheClass.cpp

<pre>

void UTheClass::BeginPlay()
{
Super::BeginPlay();

APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);

if (PC && wTheClassWidget)
{
    TheClassWidget = CreateWidget&lt;UMyUserWidget&gt;(PC, wTheClassWidget);
}

}

void UInventoryComponent::Open()
{
if (TheClass != nullptr)
{
TheClassWidget->AddToViewport();
}
}

</pre>

Thanks for you help ! :slight_smile:

You sure TheClassWidget isn’t null?

if (TheClass != nullptr)
{
TheClassWidget->AddToViewport();
}