Zum Hauptinhalt springen
Version: latest - a1.156.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

TypeNameDefaultDescription
Blueprint Referenceblueprint_path Required parameter A custom UserWidget Blueprint to spawn

Native Widget Constructor​

Spawns a Widget passing a NativeWidget enum

local my_widget = Widget(native_widget)

Parameters

TypeNameDefaultDescription
NativeWidgetnative_widget Required parameter One of the native Widgets to spawn

🦠 Functions​

Inherited Entity Functions
Widget inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
BroadcastRemoteInRadiusEventCalls a custom remote event directly on this entity to all Players in a radius
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
CallRemotePlayersEventCalls a custom remote event directly on this entity to a list of Players
DestroyDestroys this Entity
FinishSpawnFinish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode
table of stringGetAllValuesKeysGets a list of all values keys
tableGetClassGets the class of this entity
integerGetIDGets the universal network ID of this Entity (same on both client and server)
anyGetValueGets a Value stored on this Entity at the given key
booleanHasAuthorityGets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsBeingDestroyedReturns true if this Entity is being destroyed
booleanIsSpawnedGets if this Entity finished spawning
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetSpawnModeOverrides when this Entity finishes spawning, from the Constructor of an Inherited Class
SetValueSets a Value in this Entity
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
ReturnsNameDescription
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
functionBindBlueprintEventDispatcherAssigns and Binds a Blueprint Event Dispatcher
BringToFrontPuts this Widget in the front of all WebUIs and Widgets
varargs of anyCallBlueprintEventCalls a Blueprint Event or Function
anyGetBlueprintPropertyValueGets a Blueprint Property/Variable value
WidgetVisibilityGetVisibilityReturns the current WebUI visibility
SetBlueprintPropertyValueSets a Blueprint Property/Variable value directly
SetContentForSlotSets the widget for a given slot by name, if this is a UserWidget
SetFocusEnables the focus on this Widget (i.e. can receive Keyboard input and will trigger input events)
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
SetVisibilitySets the visibility in screen
Widget3DSpawnWidget3DSpawns a 3D Widget actor rendering this Widget in the world
UnbindBlueprintEventDispatcherUnbinds a Blueprint Event Dispatcher

Moderate

AddChild​

Adds a new child widget to this Widget container, if this is a Panel
my_widget:AddChild(other)

Parameters

TypeParameterDefaultDescription
WebUI or Widgetother Required parameter The WebUI or Widget to add

Moderate

AddToViewport​

Adds it to the game's viewport and fills the entire screen
my_widget:AddToViewport()

Slow

BindBlueprintEventDispatcher​

Assigns and Binds a Blueprint Event Dispatcher
local ret = my_widget:BindBlueprintEventDispatcher(dispatcher_name, callback)

Parameters

TypeParameterDefaultDescription
stringdispatcher_name Required parameter Event Dispatcher name
functioncallback Required parameter Callback function to call with this format

Returns

TypeDescription
functionthe callback itself

Optimal

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

Slow

CallBlueprintEvent​

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

TypeParameterDefaultDescription
stringevent_name Required parameter Event or Function name
anyarguments...?nil
Sequence of arguments to pass to the event

Returns

TypeDescription
varargs of anythe function return values

Slow

GetBlueprintPropertyValue​

Gets a Blueprint Property/Variable value
local ret = my_widget:GetBlueprintPropertyValue(property_name)

Parameters

TypeParameterDefaultDescription
stringproperty_name Required parameter Name of the Blueprint variable

Returns

TypeDescription
anythe value

See also SetBlueprintPropertyValue.


Optimal

GetVisibility​

Returns the current WebUI visibility
local visibility = my_widget:GetVisibility()

Returns

TypeDescription
WidgetVisibilityCurrent WebUI visibility

See also SetVisibility.


Slow

SetBlueprintPropertyValue​

Sets a Blueprint Property/Variable value directly
my_widget:SetBlueprintPropertyValue(property_name, value)

Parameters

TypeParameterDefaultDescription
stringproperty_name Required parameter Name of the Blueprint variable
anyvalue Required parameter The value to set

See also GetBlueprintPropertyValue.


Moderate

SetContentForSlot​

Sets the widget for a given slot by name, if this is a UserWidget
my_widget:SetContentForSlot(slot_name, widget?)

Parameters

TypeParameterDefaultDescription
stringslot_name Required parameter Name of the Named Slot
Widgetwidget?nil
Pass nil to remove it

Optimal

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

Moderate

SetSlotAlignment​

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

TypeParameterDefaultDescription
WidgetHorizontalAlignmenthorizontal_alignment?WidgetHorizontalAlignment.Fill
Horizontal alignment for the slot
WidgetVerticalAlignmentvertical_alignment?WidgetVerticalAlignment.Fill
Vertical alignment for the slot

Optimal

SetSlotCanvasLayout​

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

TypeParameterDefaultDescription
Vector2Dlocation?Vector(0, 0)
Screen location, or the left and top offsets when the anchors are stretched
Vector2Dsize?Vector(0, 0)
Size, or the right and bottom offsets when the anchors are stretched
Vector2Danchors_min?Vector(0, 0)
Min anchor, from (0, 0) top-left to (1, 1) bottom-right
Vector2Danchors_max?Vector(1, 1)
Max anchor, from (0, 0) top-left to (1, 1) bottom-right
Vector2Dalignment?Vector(0.5, 0.5)
Pivot of the Widget, (0.5, 0.5) is the center

Moderate

SetSlotPadding​

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

TypeParameterDefaultDescription
Vector2Dpadding_horizontal?Vector2D(0, 0)
Horizontal padding for the slot
Vector2Dpadding_vertical?Vector2D(0, 0)
Vertical padding for the slot

Moderate

SetSlotSize​

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

TypeParameterDefaultDescription
floatsize?0.0
Size value for the slot
WidgetSizeRuleslate_size_rule?WidgetSizeRule.Automatic
Size rule for the slot

Moderate

SetVisibility​

Sets the visibility in screen
my_widget:SetVisibility(visibility)

Parameters

TypeParameterDefaultDescription
WidgetVisibilityvisibility Required parameter The new visibility in screen

See also GetVisibility.


Slow

SpawnWidget3D​

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

TypeParameterDefaultDescription
Vectorlocation?Vector(0, 0, 0)
World location
Rotatorrotation?Rotator(0, 0, 0)
World rotation
WidgetSpacewidget_space?WidgetSpace.World
Whether it renders in the world or always facing the screen
booleanauto_size?false
Whether to size it automatically based on its content
Vector2Dsize?Vector2D(500, 500)
Only works if auto_size = false
floatauto_repaint_rate?-1
Leaves -1 to repaint every frame
Vector2Dpivot?Vector2D(0.5, 0.5)
Pivot of the widget, (0.5, 0.5) is the center

Returns

TypeDescription
Widget3DThe spawned Widget3D

Optimal

UnbindBlueprintEventDispatcher​

Unbinds a Blueprint Event Dispatcher
my_widget:UnbindBlueprintEventDispatcher(dispatcher_name, callback?)

Parameters

TypeParameterDefaultDescription
stringdispatcher_name Required parameter Event Dispatcher name
functioncallback?nil
Optional callback to unbind

🚀 Events​

Inherited Entity Events
Widget inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegisterTriggered when a new Class is registered with the Inheriting System
DestroyTriggered when an Entity is destroyed
SpawnTriggered when an Entity is spawned/created
ValueChangeTriggered when an Entity has a value changed with :SetValue()

This class doesn't have own 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.