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

Is your UWidgetComponent instantiated correctly in the CDO?
Perhaps it is the null pointer?

do you have something like this in your constructor?

LockedOnWidget= CreateDefaultSubobject<UWidgetComponent>(TEXT("Locked on widget"));
	LockedOnWidget->SetupAttachment(GetRootComponent());