Skip to main content
Version: latest - a1.172.0 โš–๏ธ

๐ŸชŸ Widget

The Widget class supports spawning Unreal Widgets classes through scripting and manipulate them such as Blueprints!

๐Ÿ‘ชInheritance
This class shares methods and events from Base Entity.

The Widget class allows a very versatile way to create and use Unreal widgets as UI within the game.

Note

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 Native Text and adding it to screenโ€‹

Client/Index.lua
local my_text = Widget(NativeWidget.Text)
my_text:CallBlueprintEvent("SetText", "Hello World!")
my_text:AddToViewport()
tip

SetText is a method from UTextBlock, the Widget associated to NativeWidget.Text.

Creating a Widgets with Childsโ€‹

Client/Index.lua
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โ€‹

Client/Index.lua
local webui = WebUI("mywebui", "https://google.com", WidgetVisibility.Hidden)

local my_image = Widget(NativeWidget.Image)
my_image:CallBlueprintEvent("SetBrushFromMaterial", webui)
my_image:AddToViewport()
tip

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โ€‹

Client/Index.lua
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()

๐Ÿ“š Libraries & Frameworksโ€‹

Here a list of Community Created Libraries & Frameworks making use of Widgets expanding it's possibilities:

๐Ÿ›  Constructorsโ€‹

UserWidget Constructorโ€‹

Spawns a Widget passing a UserWidget blueprint

local my_widget = Widget(blueprint_path)
Parameters
NameTypeDescription
blueprint_pathBlueprint ReferenceA custom UserWidget Blueprint to spawn

Native Widget Constructorโ€‹

Spawns a Widget passing a NativeWidget enum

local my_widget = Widget(native_widget)
Parameters
NameTypeDescription
native_widgetNativeWidgetOne of the native Widgets to spawn

๐Ÿฆ  Functionsโ€‹

Blueprints
BindBlueprintEventDispatcher: functionAssigns and Binds a Blueprint Event Dispatcher
CallBlueprintEvent: varargs of anyCalls a Blueprint Event or Function
GetBlueprintPropertyValue: anyGets a Blueprint Property/Variable value
SetBlueprintPropertyValueSets a Blueprint Property/Variable value directly
UnbindBlueprintEventDispatcherUnbinds a Blueprint Event Dispatcher
Layout
AddChildAdds a new child widget to this Widget container, if this is a Panel
AddToViewportAdds it to the game's viewport and fills the entire screen
BringToFrontPuts this Widget in the front of all WebUIs and Widgets
GetVisibility: WidgetVisibilityReturns the current WebUI visibility
SetFocusEnables the focus on this Widget
SetVisibilitySets the visibility in screen
SpawnWidget3D: Widget3DSpawns a 3D Widget actor rendering this Widget in the world
Slots
SetContentForSlotSets the widget for a given slot by name, if this is a UserWidget
SetSlotAlignmentSets the slot alignment for horizontal and vertical positioning
SetSlotCanvasLayoutSets the Layout as Canvas on Screen
SetSlotPaddingSets the slot padding for horizontal and vertical spacing
SetSlotSizeSets the slot size and size rule

Blueprintsfunctionsโ€‹

BindBlueprintEventDispatcherSlowโ€‹

Assigns and Binds a Blueprint Event Dispatcher

local ret = my_widget:BindBlueprintEventDispatcher(dispatcher_name, callback)
Parameters
NameTypeDescription
dispatcher_namestringEvent Dispatcher name
callbackfunctionCallback function to call with this format
Returns
TypeDescription
functionthe callback itself

CallBlueprintEventSlowโ€‹

Calls a Blueprint Event or Function

Returns all Function return values on Client Side

local ret_01, ret_02, ... = my_widget:CallBlueprintEvent(event_name, arguments...?)
Parameters
NameTypeDescription
event_namestringEvent or Function name
arguments...?anySequence of arguments to pass to the event Default nil
Returns
TypeDescription
varargs of anythe function return values

GetBlueprintPropertyValueSlowโ€‹

Gets a Blueprint Property/Variable value

local ret = my_widget:GetBlueprintPropertyValue(property_name)
Parameters
NameTypeDescription
property_namestringName of the Blueprint variable
Returns
TypeDescription
anythe value

See also SetBlueprintPropertyValue.

SetBlueprintPropertyValueSlowโ€‹

Sets a Blueprint Property/Variable value directly

my_widget:SetBlueprintPropertyValue(property_name, value)
Parameters
NameTypeDescription
property_namestringName of the Blueprint variable
valueanyThe value to set

See also GetBlueprintPropertyValue.

UnbindBlueprintEventDispatcherOptimalโ€‹

Unbinds a Blueprint Event Dispatcher

my_widget:UnbindBlueprintEventDispatcher(dispatcher_name, callback?)
Parameters
NameTypeDescription
dispatcher_namestringEvent Dispatcher name
callback?functionOptional callback to unbind Default nil

Layoutfunctionsโ€‹

AddChildModerateโ€‹

Adds a new child widget to this Widget container, if this is a Panel

my_widget:AddChild(other)
Parameters
NameTypeDescription
otherWebUI or WidgetThe WebUI or Widget to add

AddToViewportModerateโ€‹

Adds it to the game's viewport and fills the entire screen

my_widget:AddToViewport()

BringToFrontOptimalโ€‹

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()

GetVisibilityOptimalโ€‹

Returns the current WebUI visibility

local visibility = my_widget:GetVisibility()
Returns
TypeDescription
WidgetVisibilityCurrent WebUI visibility

See also SetVisibility.

SetFocusOptimalโ€‹

Enables the focus on this Widget

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()

SetVisibilityModerateโ€‹

Sets the visibility in screen

my_widget:SetVisibility(visibility)
Parameters
NameTypeDescription
visibilityWidgetVisibilityThe new visibility in screen

See also GetVisibility.

SpawnWidget3DSlowโ€‹

Spawns a 3D Widget actor rendering this Widget in the world

local widget_3D = my_widget:SpawnWidget3D(location?, rotation?, widget_space?, auto_size?, size?, auto_repaint_rate?, pivot?)
Parameters
NameTypeDescription
location?VectorWorld location Default Vector(0, 0, 0)
rotation?RotatorWorld rotation Default Rotator(0, 0, 0)
widget_space?WidgetSpaceWhether it renders in the world or always facing the screen Default WidgetSpace.World
auto_size?booleanWhether to size it automatically based on its content Default false
size?Vector2DOnly works if auto_size = false Default Vector2D(500, 500)
auto_repaint_rate?floatLeaves -1 to repaint every frame Default -1
pivot?Vector2DPivot of the widget, (0.5, 0.5) is the center Default Vector2D(0.5, 0.5)
Returns
TypeDescription
Widget3DThe spawned Widget3D

Slotsfunctionsโ€‹

SetContentForSlotModerateโ€‹

Sets the widget for a given slot by name, if this is a UserWidget

my_widget:SetContentForSlot(slot_name, widget?)
Parameters
NameTypeDescription
slot_namestringName of the Named Slot
widget?WidgetPass nil to remove it Default nil

SetSlotAlignmentModerateโ€‹

Sets the slot alignment for horizontal and vertical positioning

Note: This method only works if this Widget is child of one of: HorizontalBoxSlot, VerticalBoxSlot, OverlaySlot, SizeBoxSlot, ScrollBoxSlot, BackgroundBlurSlot, BorderSlot, ButtonSlot, ScaleBoxSlot, UniformGridSlot, GridSlot

my_widget:SetSlotAlignment(horizontal_alignment?, vertical_alignment?)
Parameters
NameTypeDescription
horizontal_alignment?WidgetHorizontalAlignmentHorizontal alignment for the slot Default WidgetHorizontalAlignment.Fill
vertical_alignment?WidgetVerticalAlignmentVertical alignment for the slot Default WidgetVerticalAlignment.Fill

SetSlotCanvasLayoutOptimalโ€‹

Sets the Layout as Canvas on Screen

Note: This method only works if this Widget is child of a Canvas Panel.

Anchors:

my_widget:SetSlotCanvasLayout(location?, size?, anchors_min?, anchors_max?, alignment?)
Parameters
NameTypeDescription
location?Vector2DScreen location, or the left and top offsets when the anchors are stretched Default Vector(0, 0)
size?Vector2DSize, or the right and bottom offsets when the anchors are stretched Default Vector(0, 0)
anchors_min?Vector2DMin anchor, from (0, 0) top-left to (1, 1) bottom-right Default Vector(0, 0)
anchors_max?Vector2DMax anchor, from (0, 0) top-left to (1, 1) bottom-right Default Vector(1, 1)
alignment?Vector2DPivot of the Widget, (0.5, 0.5) is the center Default Vector(0.5, 0.5)

SetSlotPaddingModerateโ€‹

Sets the slot padding for horizontal and vertical spacing

Note: This method only works if this Widget is child of one of: HorizontalBoxSlot, VerticalBoxSlot, OverlaySlot, SizeBoxSlot, ScrollBoxSlot, BackgroundBlurSlot, BorderSlot, ButtonSlot, GridSlot

my_widget:SetSlotPadding(padding_horizontal?, padding_vertical?)
Parameters
NameTypeDescription
padding_horizontal?Vector2DHorizontal padding for the slot Default Vector2D(0, 0)
padding_vertical?Vector2DVertical padding for the slot Default Vector2D(0, 0)

SetSlotSizeModerateโ€‹

Sets the slot size and size rule

Note: This method only works if this Widget is child of one of: HorizontalBoxSlot, VerticalBoxSlot, ScrollBoxSlot

my_widget:SetSlotSize(size?, slate_size_rule?)
Parameters
NameTypeDescription
size?floatSize value for the slot Default 0.0
slate_size_rule?WidgetSizeRuleSize rule for the slot Default WidgetSizeRule.Automatic

๐Ÿš€ Eventsโ€‹

This class doesn't have own events.

Inherited events

From Entity4 events

โœ… NativeWidgets to Unreal Widgets Relationโ€‹

List of the relation Unreal native Widgets โ†” NativeWidget Enums:

EnumUnreal ClassIs Panel
NativeWidget.BorderBorderโœ…
NativeWidget.ButtonButtonโœ…
NativeWidget.CheckBoxCheckBoxโœ…
NativeWidget.ImageImageโŒ
NativeWidget.ProgressBarProgressBarโŒ
NativeWidget.RichTextBlockRichTextBlockโŒ
NativeWidget.SliderSliderโŒ
NativeWidget.TextTextBlockโŒ
NativeWidget.ComboBoxComboBoxโŒ
NativeWidget.EditableTextEditableTextโŒ
NativeWidget.EditableTextMultiLineMultiLineEditableTextโŒ
NativeWidget.SpinBoxSpinBoxโŒ
NativeWidget.TextBoxEditableTextBoxโŒ
NativeWidget.TextBoxMultiLineMultiLineEditableTextBoxโŒ
NativeWidget.CanvasPanelCanvasPanelโœ…
NativeWidget.GridPanelGridPanelโœ…
NativeWidget.HorizontalBoxHorizontalBoxโœ…
NativeWidget.OverlayOverlayโœ…
NativeWidget.ScaleBoxScaleBoxโœ…
NativeWidget.ScrollBoxScrollBoxโœ…
NativeWidget.SizeBoxSizeBoxโœ…
NativeWidget.UniformGridPanelUniformGridPanelโœ…
NativeWidget.VerticalBoxVerticalBoxโœ…
NativeWidget.WrapBoxWrapBoxโœ…
NativeWidget.BackgroundBlurBackgroundBlurโœ…

โœ… List of Supported Parameter Typesโ€‹

See all Supported Parameter Types in the Blueprint Page.