How can I make a UI text binding with a C++ variable?

I want to display health on my UI widget, but it’s a variable that I declared in the C++ file of a different class. How can I reference this variable in the UI’s blueprints? I’m pretty new to blueprints.

Thanks in advance!

Edit: I couldn’t find anything helpful that told me how to do this anywhere so in case someone is trying to figure this out, here is what I did:

  1. Drag a text widget onto the canvas panel.

  2. Click the “Content” submenu along the right side of the new text widget.

  3. To the right of “Text” and “”, click the “Bind” button, then “Create Binding.”

  4. It will pull you into the blueprint of that new binding. From the “Return Node”, drag from “Return Value” out onto the graph to be prompted for a new node.

  5. Type in “cast to [the name of the blueprint class derived from the C++ class that the variable is declared in*]”

  6. Select the corresponding action.

  7. Drag out “As [class name]” to create a new node.

  8. Search “Get [variable name]”.

  9. Drag out from that node and search “ToText [variable type]”.

  10. Link that “ToText” node’s “Return Value” to the “Return Node’s” “Return Value”.

  11. Now drag out “Object” from “Cast To […]” and search “Get Player Character”. If you’re variable is from somewhere else, like the PlayerController, then type “Get [that]” instead.

  12. Finally, link the first “[Function Name]” node to “Cast To […]”, then link that node to the “Return Node”, compile, and run.

*I think the variable needs to be declared under “public:” and somewhat like this:

UPROPERTY (VisibleAnywhere, BlueprintReadOnly, Category="PlayerVariables /* or whatever category the variable is in */")
// variable initialization:
int32 Health;

Additionally, you might need to uncheck “Context Sensitive” when creating a new node.

I know that this is a very simple thing but it took me a while to figure out and I couldn’t find anything that could tell me.