My c++ class cant see a variable in my blueprint

Hi there, Im a super noob to c++,

I have created a c++ project and created three blueprints. I basically have a umg widget menu. There is a main menu with a ‘new project’ button, and an ‘Open project’ button. There are blueprints for each of these buttons.

The user can select a new project, it goes to the New project blueprint and I have a plugin which creates a windows dialogue box which pops up and allows them to store a folder location for the project. - It stores this string location in a variable called ‘ProjectFolder’ - which is bound to a text box in the menu so you can see the selection. - The text box is called ‘FolderLocation_TxtBox’, and isVariable.

The user can also select the ‘Open Project’ button and press the folder icon to select a particular file. This file location is stored in ‘FileLocation’ variable and bound to a similar text block variable ‘FileLocation_TxtBox’.

In my main menu. which is derived from a c++ class. I have accessed these two other blueprints and found all widgets and promoted the respective text box variables to a local variable to the main menu blueprint. These new variable names are 'New_ProjectFolder_REF ’ and 'OpenProject_FileLocation_REF '. I have matched the name of these promoted variables in my c++ classes.

However the issue is when I run my code, it cant see the promoted variables I created:
//A required widget binding “New_ProjectFolder_REF” of type Text was not found.
//A required widget binding “OpenProject_FileLocation_REF” of type Text was not found.

Can anyone explain to me how My code will be able to interact with referenced variables under a different name to the ones that are actually in the original blueprints.

I hope I have explained this correctly.

Sam

is this beyond comprehension?

Hi,

May you be greate.

I don’t know if I get your real problem, I hope help tough.

So since Blueprint is a child of C++, you cannot get a variable defined in the child from its parent, the correct order is get variable defined in parent from child.

Try to create the variables in C++ and instead of promote it in the blueprint, set value of the C++ version.

Another solution is create a get function that returns the desired data (be aware of the type).

 UFUNCTION(BlueprintImplementableEvent, Category = "UI")
 UUserWidget* GetDesiredWidget();

By doing this you can set this function in blueprint to and call it from C++. Just make sure the function type is correct.

To finish avoid hard reference, it’s not a good practice, instead of hard reference use event dispatcher and interfaces.

Bye.

thankyou SpecZynk. I will try and maybe set this up in c++.

I wasnt sure if I communicated it correctly. But basically the c++ class is connected to the Main Menu blueprint. But I wanted to reference values stored in a variables in other blueprints and have the values represented in the main Menu.

I find classes generally confusing to understand, but I will try and set this up in code.

thanks,
Sam