UWidgetComponent I can't demonstrate inside of AActorClass inheritance

Hello every lovely developer,

I create a UWidgetComponent inside of the AActor class inheritance but it does not demonstrate in the screen when I start the gameplay, but if I create the widget from the UE5 Editor instead of using C++ it demonstrate on the screen. What the problem I really don’t get it.

Anyone can help me the solve this problem? Or any different perspective to find out the solution?

.h

class ABaseBuilding:: public AActor,

....

UWidgetComponent* OptionsMenuWidget;
...

.cpp

OptionsMenuWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT(OptionsMenu));
OptionsMenuWidget->SetupAttachment(GetRootComponent())

If I write this code inside of the ACharacterClass is demonstrate it but not effect in AActor class.

Thanks for help

Use UPROPERTY() to expose your variable:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
TObjectPtr<UWidgetComponent> OptionsMenuWidget;

Thank you for reply, but it does not helped.

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="WidgetComponent")
UWidgetComponent* BuildingOptionsMenuWidget;

My problem is not editing the widget. The main problem is when I attach the widgetclass, it does not demonstrate inside of AActor. But it demonstra inside of ACharacter in gameplay.

Widget inside of the AActor demonstrate when I editting. But it’s not inside the gameplay.

Kind regards,

I just tested an Actor with your code and it worked.
I don’t know what is happening but make sure the Actor ( or component ) is facing the camera and at a valid distance.

Did you demonstrate as Screen or World?

Because if I demonstrate as World, I can see the widget FVector(0,0,100 ) on correct perspective of camera. But I can’t see as screen method at nowhere.

Thank you for response.

Even switching to ‘Screen’ I can still see the Widget, regardless of whether it is sideways or backwards in this case, but it needs to be in front of the camera.
Try with different Draw Sizes. I don’t know what could be happening.

By Gameplay you mean Play in Editor?

PS: In the case of Space = World: I see the Widget in the Editor’s level AND when I click Play.
In the case of Space = Screen: I only see the Widget when I click Play.

By Gameplay mean when I start the game in editor or new window.

The widget in editor looking like this, There is too many distance between widget and the Actor.
The Widget at FVector(0,0,0) in World Location ( I did not edited like that, it’s default I dont know why )

image

The widget edited in editor like this. It is really annoying because I totally locked up. I can’t go further and did not getting the problem.

Okay now there is a good update, still working on.

I re-locate the widget in gameplay next to the cube and set it to the screen.

And I can see the widget in the screen as I want.

But I have to edit manually.

It does not effect to the base, it is effect only instances.