Widget
The Widget class supports spawning Unreal Widgets classes through scripting and manipulate them such as Blueprints!
The Widget class allows a very versatile way to create and use Unreal widgets as UI within the game.
Most parameters are not exposed in the Widget class, and should be called using the method CallBlueprintEvent()
, which will call the specific underlying Widget method.
Examples
Creating a Simple a Native Text and adding it to screen
local my_text = Widget(NativeWidget.Text)
my_text:CallBlueprintEvent("SetText", "Hello World!")
my_text:AddToViewport()
SetText
is a method from UTextBlock, the Widget associated to NativeWidget.Text
.
Creating a Widgets with Childs
local my_vertical_box = Widget(NativeWidget.VerticalBox)
my_vertical_box:AddToViewport()
local my_text = Widget(NativeWidget.Text)
my_text:CallBlueprintEvent("SetText", "Hello World!")
local my_button = Widget(NativeWidget.Button)
my_vertical_box:AddChild(my_text)
my_vertical_box:AddChild(my_button)
Using a WebUI as Image Brush
local webui = WebUI("mywebui", "https://google.com", WidgetVisibility.Hidden)
local my_image = Widget(NativeWidget.Image)
my_image:CallBlueprintEvent("SetBrushFromMaterial", webui)
my_image:AddToViewport()
SetBrushFromMaterial
is a method from UImage, and expects a MaterialInstance
as parameter. Passing WebUI, SceneCapture or Canvas converts it to it's internal Material automatically when being passed as parameter!
Subscribing for a Dispatcher
local my_button = Widget(NativeWidget.Button)
-- Puts a text inside of it
local my_text = Widget(NativeWidget.Text)
my_text:CallBlueprintEvent("SetText", "Press Me!")
my_button:AddChild(my_text)
-- Binds the native OnClicked dispatcher
my_button:BindBlueprintEventDispatcher("OnClicked", function()
Console.Log("clicked!")
end)
-- Adds the button to viewport (will fill the whole screen)
my_button:AddToViewport()
Constructors
UserWidget Constructor
local my_widget = Widget(blueprint_path)
Type | Name | Default | Description |
---|---|---|---|
Blueprint Reference | blueprint_path | A custom UserWidget Blueprint to spawn |
Native Widget Constructor
local my_widget = Widget(native_widget)
Type | Name | Default | Description |
---|---|---|---|
NativeWidget | native_widget | One of the native Widgets to spawn |
Functions
Inherited Entity Functions
Returns | Name | Description | |
---|---|---|---|
integer | GetID | Gets the universal network ID of this Entity (same on both client and server) | |
table | GetClass | Gets the class of this entity | |
boolean | IsA | Recursively checks if this entity is inherited from a Class | |
function | Subscribe | Subscribes to an Event on this specific entity | |
function | SubscribeRemote | Subscribes to a custom event called from server on this specific entity | |
Unsubscribe | Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed | ||
SetValue | Sets a Value in this Entity | ||
any | GetValue | Gets a Value stored on this Entity at the given key | |
Destroy | Destroys this Entity | ||
boolean | IsValid | Returns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity) | |
CallRemoteEvent | Calls a custom remote event directly on this entity to a specific Player | ||
CallRemoteEvent | Calls a custom remote event directly on this entity | ||
BroadcastRemoteEvent | Calls a custom remote event directly on this entity to all Players |
Returns | Name | Description | |
---|---|---|---|
SetVisibility | Sets the visibility in screen | ||
WidgetVisibility | GetVisibility | Returns the current WebUI visibility | |
SetFocus | Enables the focus on this Widget (i.e. can receive Keyboard input and will trigger input events) | ||
BringToFront | Puts this Widget in the front of all WebUIs and Widgets | ||
AddToViewport | Adds it to the game's viewport and fills the entire screen | ||
AddChild | Adds a new child widget to this Widget container, if this is a Panel | ||
SetContentForSlot | Sets the widget for a given slot by name, if this is a UserWidget | ||
SetCanvasLayout | Sets the Layout as Canvas on Screen | ||
any | CallBlueprintEvent | Calls a Blueprint Event or Function | |
function | BindBlueprintEventDispatcher | Assigns and Binds a Blueprint Event Dispatcher | |
UnbindBlueprintEventDispatcher | Unbinds a Blueprint Event Dispatcher | ||
SetBlueprintPropertyValue | Sets a Blueprint Property/Variable value directly | ||
any | GetBlueprintPropertyValue | Gets a Blueprint Property/Variable value |
SetVisibility
Sets the visibility in screen
my_widget:SetVisibility(visibility)
Type | Parameter | Default | Description |
---|---|---|---|
WidgetVisibility | visibility |
GetVisibility
Returns the current WebUI visibility
— Returns WidgetVisibility.
local ret = my_widget:GetVisibility()
SetFocus
Enables the focus on this Widget (i.e. can receive Keyboard input and will trigger input events
Note: Only one Widget can have focus per time.
my_widget:SetFocus()
BringToFront
Puts this Widget in the front of all WebUIs and Widgets. Note: You can only call it if the Widget is parented to the Viewport!
my_widget:BringToFront()
AddToViewport
Adds it to the game's viewport and fills the entire screen
my_widget:AddToViewport()
AddChild
Adds a new child widget to this Widget container, if this is a Panel
my_widget:AddChild(other)
SetContentForSlot
Sets the widget for a given slot by name, if this is a UserWidget
my_widget:SetContentForSlot(slot_name, widget)
SetCanvasLayout
Sets the Layout as Canvas on Screen.
Note: This method only works if this Widget is child of a Canvas Panel.
Anchors:
my_widget:SetCanvasLayout(screen_location/offset_left_top?, size/offset_right_bottom?, anchors_min?, anchors_max?, alignment?)
Type | Parameter | Default | Description |
---|---|---|---|
Vector2D | screen_location/offset_left_top? | Vector(0, 0) | |
Vector2D | size/offset_right_bottom? | Vector(0, 0) | |
Vector2D | anchors_min? | Vector(0, 0) | |
Vector2D | anchors_max? | Vector(1, 1) | |
Vector2D | alignment? | Vector(0.5, 0.5) |
CallBlueprintEvent
Calls a Blueprint Event or Function
Returns all Function return values on Client Side
— Returns any (the function return values).
local ret = my_widget:CallBlueprintEvent(event_name, arguments...?)
Type | Parameter | Default | Description |
---|---|---|---|
string | event_name | Event or Function name | |
any | arguments...? | nil | Sequence of arguments to pass to the event |
BindBlueprintEventDispatcher
Assigns and Binds a Blueprint Event Dispatcher
— Returns function (the callback itself).
local ret = my_widget:BindBlueprintEventDispatcher(dispatcher_name, callback)
Type | Parameter | Default | Description |
---|---|---|---|
string | dispatcher_name | Event Dispatcher name | |
function | callback | Callback function to call (the first argument is the blueprint itself) |
UnbindBlueprintEventDispatcher
Unbinds a Blueprint Event Dispatcher
my_widget:UnbindBlueprintEventDispatcher(dispatcher_name, callback?)
Type | Parameter | Default | Description |
---|---|---|---|
string | dispatcher_name | Event Dispatcher name | |
function | callback? | Optional callback to unbind |
SetBlueprintPropertyValue
Sets a Blueprint Property/Variable value directly
my_widget:SetBlueprintPropertyValue(property_name, value)
GetBlueprintPropertyValue
Gets a Blueprint Property/Variable value
— Returns any (the value).
local ret = my_widget:GetBlueprintPropertyValue(property_name)
Type | Parameter | Default | Description |
---|---|---|---|
string | property_name |
Events
Inherited Entity Events
Name | Description | |
---|---|---|
Spawn | Triggered when an Entity is spawned/created | |
Destroy | Triggered when an Entity is destroyed | |
ValueChange | Triggered when an Entity has a value changed with :SetValue() | |
ClassRegister | Triggered when a new Class is registered with the Inheriting System |
Name | Description |
---|
✅ NativeWidgets to Unreal Widgets Relation
List of the relation Unreal native Widgets ↔ NativeWidget Enums:
Enum | Unreal Class | Is Panel |
---|---|---|
NativeWidget.Border | Border | ✅ |
NativeWidget.Button | Button | ✅ |
NativeWidget.CheckBox | CheckBox | ✅ |
NativeWidget.Image | Image | ❌ |
NativeWidget.ProgressBar | ProgressBar | ❌ |
NativeWidget.RichTextBlock | RichTextBlock | ❌ |
NativeWidget.Slider | Slider | ❌ |
NativeWidget.Text | TextBlock | ❌ |
NativeWidget.ComboBox | ComboBox | ❌ |
NativeWidget.EditableText | EditableText | ❌ |
NativeWidget.EditableTextMultiLine | MultiLineEditableText | ❌ |
NativeWidget.SpinBox | SpinBox | ❌ |
NativeWidget.TextBox | EditableTextBox | ❌ |
NativeWidget.TextBoxMultiLine | MultiLineEditableTextBox | ❌ |
NativeWidget.CanvasPanel | CanvasPanel | ✅ |
NativeWidget.GridPanel | GridPanel | ✅ |
NativeWidget.HorizontalBox | HorizontalBox | ✅ |
NativeWidget.Overlay | Overlay | ✅ |
NativeWidget.ScaleBox | ScaleBox | ✅ |
NativeWidget.ScrollBox | ScrollBox | ✅ |
NativeWidget.SizeBox | SizeBox | ✅ |
NativeWidget.UniformGridPanel | UniformGridPanel | ✅ |
NativeWidget.VerticalBox | VerticalBox | ✅ |
NativeWidget.WrapBox | WrapBox | ✅ |
NativeWidget.BackgroundBlur | BackgroundBlur | ✅ |
✅ List of Supported Parameter Types
See all Supported Parameter Types in the Blueprint Page.