This guide will go through creating and interacting with the widget.
For more detailed information about widgets, visit:
UMG UI Designer Quick Start Guide on UnrealEngine documentation.
- Create the widget by right-clicking in the Content Browser -> User Interface -> Widget Blueprint, and select the User Widget under Common.
- You can rename it or use the default name for the Widget Blueprint you created.
Name it with the prefixWBP_
(WidgetBlueprint) followed by a suitable name for that widget, for this example:WBP_MyWidget
- Double-click on the created widget, and at the top-left side, search for
Canvas
and drag it onto the hierarchy root object.
- Do the same with,
Text
but drop it on top of the canvas panel.
- Set it as a variable, name it, and adjust its location as you wish.
Note
For more infomation about the widget layout/panels, visit: Widget Blueprints on UE documentation.
- Navigate to the Event Graph of the widget, and create a new custom event, by right-clicking and searching for
custom
.
- Name it
SetPositionText
. - Add a new Input variable, of type Vector.
- Create the following logic as shown in the image below.
- Navigate to the ModActor of your mod, and add a node called
Create Widget
. - Plug it into BeginPlay, so it creates the widget when the mod actor spawns.
- Provide the widget class in the Class field.
- Create and plug the
Add to Viewport
as shown in the image below.
In order to use and access the newly created widget, we need to store it in a variable.
- Drag the Return value of the widget, and promote it to a variable.
For this simple example, we will get the player pawn location on the event tick, and use the widget's method to set the position text.
Tip
Avoid directly accessing the text component outside of the widget like in mod actor BP, try using methods to ensure low coupling between objects.
We've created a simple custom widget where we can directly access it and call methods.
It's common practice to ensure the displayed data is easily understandable and readable.
For example:
- Formatting/appending the text with a description of the following data.
- For vector types, divide the vector by
100
units for easy readability.