Sharing a SverticalBox between BP and c++?

Hi,

How do i share a SVerticalBox between blueprint and c++ ?

I’d like to fill a SVerticalBox in c++.

I see two possible strategies:

  • create the SVerticalBox in c++ and expose it to the BP

  • create the SVerticalBox in the BP and pass it to an exposed c++ function

I could succeed in none of those.

The following code is in the UUserWidget that the BP inherits from.

The problem is that those 4 tries give me an “unrecognized type” at compilation (TSharedPrt or SVerticalBox).

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = yag)
	SVerticalBox* ResolutionBox;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = yag)
	TSharedPtr<SVerticalBox> ResolutionBox;

UFUNCTION(BlueprintCallable, Category = "Yag")
	void SetupResolutions(SVerticalBox* ResolutionBox);

UFUNCTION(BlueprintCallable, Category = "Yag")
	void SetupResolutions(TSharedPtr<SVerticalBox> ResolutionBox);

This one:

UFUNCTION(BlueprintCallable, Category = "Yag")
	void SetupResolutions(UUserWidget* UResolutionBox);

is compiling but within my function i don’t know how to go from a UUserWidget to a SVerticalBox.

I tried different combinations of Casting, TSharedRef, TSharedPtr, couldn’t find one that works.

Thanks for any pointers (pun almost intended^^) in the right direction !

Cedric

Still no answer but a cool workaround in case anyone is stuck too.

I use the FindWidget function:

UVerticalBox* UVerticalBox_Resolutions = (UVerticalBox*)(WidgetTree->FindWidget(FName(TEXT("VerticalBox_Resolutions"))));

In my UMG widget i create a verticalbox named “VerticalBox_Resolutions”, and in the code i add the hereabove line.

I’ll mark this as solved as it works well, but if anyone has a better solution that would answer directly my initial question, please do share it :slight_smile:

Cheers

Cedric