c++ how to access a widget inside a main HUD widget

Hi guys, I have a problem with getting a widget inside another widget (main HUD widget which has all other widget panels inside it, like inventory, character, crafting panel etc…)

So I have a main HUD_01 widget and a Inventory Widget. The inventory widget is added to the HUD_01 and placed appropriately on the canvas.

I’m trying to set the visibility of the inventory panel to visible in my PlayerController on pressing “I”. I’m starting out by trying to set visibility to true in Beginplay for building it up step by step.

I have set the variables for HUDWidgetClass and MyHUD_01 in the editor in the player controller.

In my HUD_01.h I have the following code:

UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UUserWidget* MyInventory;

In PlayerController.h I have this:

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Edit")
	TSubclassOf<class UUserWidget> HUDWidgetClass;

	UPROPERTY()
	UUserWidget* HUDReference;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Edit")
	TSubclassOf<class UHUD_01> MyHUD_01;

In PlayerController.cpp I have the following:

void AKSPlayerController::BeginPlay()
{
	Super::BeginPlay();

	if (HUDWidgetClass != nullptr) {
		HUDReference = CreateWidget<UUserWidget>(this, HUDWidgetClass);
		HUDReference->AddToViewport(10);

		if (MyHUD_01 != nullptr) {
			MyHUD_01.MyInventory->SetVisibility(true);
		}
		
	}

}

The error is on MyHUD_01.MyInventory! It can’t find the variable MyInventory on the HUD_01 class!

Any ideas how I can reach the MyInventory widget inside HUD_01 and toggle it’s visibility?

Thanks in advance!

hello, I do it as follows:

link

If you want to hide or unhide a widget within your UUserWidget class, you must obtain the WidgetTree and make reference to your widget be a button panel etc.

Thanks! I will check it out once I have time again to work on the project!

okay. Here I leave more information about the widget

UE4Slate and Native UMG(C++) Notes