How to set the widget class to none in c++

Sry for the late reply I was busy all day. I forgot to mention that the function setting the widget is in the pawn class and gets called in the character class under certain conditions but I debugged it previously and what’s crashing it is setting it to NULL or nullptr and idk why.
Here’s the function:

void ATargetDummy::EnableWidget()
{
	if (LockedOnWidget->GetWidgetClass() != nullptr)
	{
		LockedOnWidget->SetWidgetClass(nullptr);
	}
	else
	{
		LockedOnWidget->SetWidgetClass(WidgetBPContainer);
	}
}

Btw WidgetBPContainer is a TSubclassOf and it doesn’t crash when I set it in the function but idk no widget displays when it’s set.