Do i have to create blueprint actor to access widget?

I created most of my game in C++, and made it part of the challenge to do so. So no blueprints.
But now it comes the part of the UI and im super confused on how do i make this work without having to make Blueprints out of all the actors that will need to be represent in the UI, or access or modify variables in it.

When i create a new actor that needs to use or modify stuff in another actor, i include it.
But since Widgets are made in the editor, then i cant do this.

I could do the widget fully in C++, but the UI i really dont want to do it all in C++. I really like UMG, because we can see it and modify it live.

So how can i make a Widget, and customize it in the editor (BP), add images to it etc… And then in C++ change its variables. and communicate with it.

For example. I have units that are made fully in C++.
How do i from a C++, access and modify a variable that is in a BP Widget, if my C++ actor is not a blueprint?
So for example I have float UnitHealth. After the unit takes damage, how do i tell the BP Widget to change itself, if my Unit is C++, and the widget is BP.

Make the widget in c++ based on UUserWidget. Add in all variables you want to change via c++ and you can make them visible in UMG via BindWidget

UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
class UTextBlock* TitleLabel;

UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
class UImage* IconImage;

To add this widget reference in a class use

UPROPERTY(BlueprintReadWrite,editAnywhere)
TSubClassOf<UMyCustomUserWidgetClass> widget;

Then you can assign the widget to your blueprint widget implementation (that derives from your custom UUserWidget variant)

1 Like

thanks so much.
So basically this will BIND.
Is this like the BIND that we see in the UMG editor?
Because one time i was using this Bind and a friend of mine told me not to use it.
Because we are going to need a lot of that, and if we bind it all its not going to be good for performance.
So we did all the UMG stuff without BINDING anything and it worked.
So is this bind like that bind?
Can we not change the variable directly?


I mean like this bind here ^.
My friend told me to avoid this.
So basically. All i want is to be able to draw the stuff and put images and buttons in the editor.
And interact with it in C++ as if it was another class. But preferably without bindings?

I thought maybe i could create an intermediary actor in c++.
There i have functions that are then overriden in BP.
Then in Blueprint i use this Intermediary actor overriden functions to communicate and change the UI.
So now in C++, all i have to do is include this intermediary actor in all the actors that i need to change the UI.
Call the function of the intermediary, will call the blueprint code that will interact with the BP WIDGET.
Is this a good alternative?

Yes this seems to be the bind equivalent in c++ so it will be polled every frame.
You can do a UFUNCTION with an override and implement it in the widget on the blueprint side if you want it to be event driven.

1 Like

Thanks.
So thats what i will do.
Just create an actor that is specifically created just be the intermediary between my C++ units and the UMG.
I think thats more clean.
I never liked stuff ticking and polling every frame :slight_smile: