Unable to Set Widget Variable when Created in C++

Hello! I’m working on creating a menu with a combination of UMG and C++.

The visuals will be made with UMG Blueprints, but want to reference them in C++ so I can hook up their functionality there.

I first created a C++ class and added a Widget Switcher reference to it. With UPROPERTY, I was able to expose this in Blueprints:

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "WidgetSwitcher.h"
#include "TestWidget.generated.h"

/**
 * 
 */
UCLASS(Blueprintable)
class GCMACPREVIEW_API UTestWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
    virtual void NativeConstruct() override;
    
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Parent Widgets")
    UWidgetSwitcher* MenuWidgetSwitcher = nullptr;
};

I then created a Blueprint off this class (tried directly creating from C++ class and reparenting when created from UserWidget) and I could see my reference I had created.

I then created a variable in the Blueprints graph called “BP Switcher” and made it instance editable:

With these created, I added a UMG Widget Switcher called “WidgetSwitcher_180”. This is listed as an option to reference by my variables, but only the BP-created value can be set. The C++ variable just remains blank when I select the option:

The main reason I cannot use the “meta=(BindWidget)” option is because I am setting this value when it is the child of another widget (see photo below):

Is there some other setting I need to set so I can reference my Blueprint Widget in C++?

When you use the specifier “Blueprintable” do you create a blueprint class based off the C++ class by right clicking the content browser and asking to create a new BP class then typing in the name of your C++ class? (I see you tried re-parenting, but that is not the ideal way to create the blueprint).

Also, can you give better screen shots? It is hard to tell where you are attempting to set this variable. And from what menu/details panel.

Hi, look here, this is going to help you. I developed them recently for 4.22. the corrections are in the answer. I leave the link:

link text

Thank you for your response. Unfortunately, I cannot use BindWidget to reference the value because it is referencing a widget in the parent widget.

I updated my question with a sample project to give more information.

I created a blank project and tried creating the Blueprint class directly from by C++ class, but it has the same result unfortunately.

Sure! I updated the question and images and created a blank project to help focus on the issue I’m having.

Bump.

Unfortunately, I still cannot resolve this issue. :frowning: As a workaround, I need to create a dummy BP, create duplicate variables in BP mirroring the C++ variables, and set the BP variables to the C++ variables in the Construct function. This dummy BP is then inherited by other UMG’s where I can set my BP variable references.

Though this works now, if I need to track 100 variables in C++, that would mean I would have to create an extra 100 variables in BP and set them individually to each C++ variable, which would be very cumbersome.

I’ve been experiencing this as well, would be nice if Epic could sort this out. Seems like a bug to me.