How can I reference a HUD Blueprint in a C++ class?

Hello.
I’m trying to reference my HUD BP in C++ class, because I need to change a variable inside of it.
Can you tell me how can I manage this?

Setting the value in C++

So I just tried that, but I have a problem - I need to reference a specific object in my C++ class in order to change it’s value. How do I do that?

If the variable you want to change is defined in Blueprint ONLY, it cannot be done, because you can only expose C++ to Blueprint, not Blueprint to C++.

There is a workaround however:
Create a C++ baseclass for your HUD BP class, and define the variable inside it. You can then proceed to use this variable in BP like before, and in C++ you can access a variable of that baseclass and modify the member.

Hmmm… Alright, thanks. I’ll just create HUD in C++, but can you tell me how can I add a widget to viewport in C++?

That’s what I get from trying to do stuff in Blueprints… Never again

ok one moment. what exactly do you mean by “changing the variable inside of it”? Do you mean setting the value in C++ code? Or through the Details Panel inside the editor?

Well you just reparent your existing blueprint to the c++ class you created and expose the variable in the C++ class with UPROPERTY(EditAnywhere, BlueprintReadWrite), then everything should be like before on the blueprint side. You can then use blueprint again to add it to the viewport.

Ok. Thank you very much!