There are ways to access Blueprint variables in C++ but it’s not pretty and normally not recommended.
If you know this widget will have these variables, you’re better off just creating a new Widget (UMyProgressBarWidget) that inherits from UUserWidget and has those as simple C++ UPROPERTIES with BlueprintReadWrite so they can be accessed via Blueprints as well.
The best practice is to make a base C++ user widget class that contains all the things that you need to access from c++ and then make your umg blueprint inherit from that class.
My advice for you is: make as much as you can in C++. It seems to be more work, but, in the end, it’s easier to maintain and do what you need.
If it help you, a few steps I’d recommend you doing.
Start by creating a [FONT=courier new]MyGameBaseWidget class (sample name, ofc), which inherits from [FONT=courier new]UUserWidget. If you have function/variables common to all the widgets you’re going to create, you’re free to add them here.
Create a [FONT=courier new]UCircleProgressBaseWidget[FONT=courier new] which inherits from [FONT=courier new]MyGameBaseWidget
Create component pointers at c++ level (while this is optional and used for optimization, it’s a good idea to have these) for stuff you will need to access directly from the code. I.e.: [FONT=courier new]UEditableTextBox* EditableBoxPtr;
Tied with step 3 (so, if you skipped it, you won’t need this function, but will need to understand how it works), you need to get the custom component from the blueprint, so do this:
(Remember to set it to [FONT=courier new]nullptr in the constructor too!)
If you have a child blueprint in this blueprint, you can refer it to as [FONT=courier new]UUserWidget*
Edit the target data. Of course, C++ only recognizes the basic elements defined in code, such as [FONT=courier new]UEditableTextBox in the example above.
This is one way of doing it. There’s ways to call a BP only function too, but it’s kinda slow…
If I had to call a BP function, I’d do it either as BlueprintCallable, to define it in C++ and use as much C++ as possible (while harder to do, it’s easier to maintain, IMO) or some other UFUNCTION flag that helps me in the process. Looking up names in BP is expensive and should be avoided as much as possible (hence, that strategy of steps 3 and 4 of having a pointer cache!)
I hope that helps! Post back with your results if you can, please
Its actually not that hard once you get used to it. So first, make a C++ class inheriting from UUserWidget. Then make the blueprint inherit from the C++ class you just created. Now for a simple button, just do this.
example:
in the header
UPROPERTY(meta = (BindWidget))
class UButton *MyCoolButton;
protected:
virtual bool Initialize() override; // override this, its like beginplay but for UUserWidgets
Now make the widget component in the BP with the exact same name as in C++ (so in the above example, name it MyCoolButton). Then everything should work. Your widget designs can be in BP but the logic for them is in C++.