[C++] UUserWidget - How to add simple text?

Hello!

What i want to do:

I’ve dynamically created UUserWidget inside my AAcor class. Now i’m wondering how to add something to it. For example, simple text and edit its propeties.

Example:

If it’s not possible

: How to load already created widget?


Cheers,
Cookie

If I understand correctly, you wan’t to be able to add the text from C++, right? In that case, I’m pretty sure you’d have to look into Slate, as UMG is only a wrapper for Slate, which can be edited from inside the editor.

For your second question: You would create a BlueprintImplementableEvent for example on your PlayerController and call that function from your C++ code when you want to create the Widget. The function could return a pointer to the created widget (or better the UTextBlock within that widget), so you can edit the text inside your code.

In your PlayerController-Blueprint, you would override the function and create a widget, as you would normally from Blueprints, and return the created widget.

Hope this helps

Cheers, Elewyth

■■■■, it looks like a lot of work. Slate itself is overwhelming. But the real question is:
If i’ll create something similar to this: https://wiki.unrealengine.com/Slate,_Hello

Will I be able to change this: .Text(LOCTEXT("HelloSlate", "Hello, Slate!"))

…directly in my c++ class?

Or maybe I have to create few slate widgets and make a reference to everyone?

I want to a simple text: “[E] To Use” appear when i’m looking at interactive object, or “[E] To Talk” when I’m looking at character".

Cheers, Cookie

In that case, i would recommend using the second method with the BlueprintImplementableEvent. If the texts you want to display are fairly fixed, you could even create separate Widgets for each text and spawn them from the Blueprint function, which you would trigger out of your C++ code. Then you wouldn’t have to bother with changing the text inside of the code.

Another improvement to the BlueprintImplementableEvent would be to pass a FString (or FText, whatever you prefer) along as a function-parameter. The blueprint which implements the function could then create the widget and set the text right away, without the code needing to know the details of how to set the text on your widget.

Alright, I did it, thanks a lot! :slight_smile: