Download

UWidetComponent not visible in game.

The ptr declaration.
declaration

and the constructor initialization.
constructor

I created a bp class inheriting from the c++ class, and the widget is visible in the viewport of the blueprint, but not in game.

What is causing this?

Do you have this somewhere in your class?

UUserWidget* theWidget;
Widget->SetWidget(theWidget);

When you call USceneComponent::SetVisibility on the WidgetComponent it won’t have any effect on the UserWidget unless if the UserWidget is already Visible.

You can’t Get a reference to the UserWidget until it is initialized which happens in UWidgetComponent::InitWidget on BeginPlay.

The Editor Viewport displays UserWidgets Default settings.
The Play-mode Viewport runs the Widget Graph which is probably why you see a difference between the Editor and Play mode.

You should ensure that the UserWidget is not being hidden somwhere in a graph.