How can I acces to widget blueprint variable in an other c++ class

Hi guys,

How can I acces to widget blueprint variable in an other c++ class ? I want to get a reference to my vertical box in a subclass of UButton. Thanks for your help.

Hey perrin_l77-

Are you referring to your button class being able to reference a specific variable inside your widget blueprint or have the class be able to reference the widget itself? If it is the latter, you should be able to add a UUserWidget pointer to your button class and assign your widget to it. If you are trying to accomplish the former (of accessing a specific variable), the setup would be the same however you would use your pointer to then access the specific variable.

Cheers

Thanks but how i can assign my widget ? Sry im a beginner in c++ and ue4.

You can use ConstructorHelpers, ConstructorHelpers::FObjectFinder < WidgetBlueprint> TempVar("WidgetBlueprint'Path\To\WidgetBP'") specifically, to get a reference to your widget blueprint from the editor. The easiest way to find the path to your blueprint is to right click on the blueprint and choose the Copy Reference choice in the menu.

Thanks a lot, have a nice day

EDIT : Hi, when i get the widget and try to acces to a specific widget, i have an error cause the variable who countains all widget is equal to NULL.

Here my code :

static ConstructorHelpers::FObjectFinder <UWidgetBlueprintGeneratedClass> tmpWidget(TEXT("WidgetBlueprint'/Game/BP_HomeScreen.BP_HomeScreen_C'"));
	
	if (tmpWidget.Object != NULL) {
		WidgetPtr = (UUserWidget *)tmpWidget.Object;
		UVerticalBox *test = (UVerticalBox *)WidgetPtr->GetWidgetFromName("VBox");
		WidgetPtr->bHiddenInDesigner = true;
	}

I get the class instead the blueprint, it might be this but when i try to get the blueprint i have the error : fail to find…

Rather than using UWidgetBlueprintGeneratedClass, if you use UUserWidget instead it should populate tmpWidget. If you are trying to find the class the blueprint belongs to rather than the blueprint itself, then you would use FClassFinder instead of FObjectFinder.

Hi,

When i replace UWidgetBlueprintGeneratedClass by UUserWidget :

 static ConstructorHelpers::FObjectFinder <UUserWidget> tmpWidget(TEXT("WidgetBlueprint'/Game/BP_HomeScreen.BP_HomeScreen'"));

i have an error : “Failed to find WidgetBlueprint’/Game/BP_HomeScreen.BP_HomeScreen’” ".

Thanks