Widget switching crashes editor

Garbage collection is likely whats causing the issue since you’re trying to remove them from the viewport when switching widgets vs just changing their visibility. Try the following code and if that doesn’t work, let me know and I’ll look into it further.

void AMyPawn::Button1()
{
	widget1->SetVisibility(ESlateVisibility::Collapsed);
	widget2->SetVisibility(ESlateVisibility::Visible);
	time = Cast<UTextBlock>(widget2->GetWidgetFromName(TEXT("Time")));
}

void AMyPawn::Button2()
{
	widget2->SetVisibility(ESlateVisibility::Collapsed);
	widget1->SetVisibility(ESlateVisibility::Visible);
	time = Cast<UTextBlock>(widget1->GetWidgetFromName(TEXT("Time")));
}