Skip to main content

Widget

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


💂Authority
This class can only be spawned on 🟧 Client side.
👪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 a 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()

Constructors

UserWidget Constructor

local my_widget = Widget(blueprint_path)
TypeNameDefaultDescription
Blueprint Referenceblueprint_pathA custom UserWidget Blueprint to spawn

Native Widget Constructor

local my_widget = Widget(native_widget)
TypeNameDefaultDescription
NativeWidgetnative_widgetOne of the native Widgets to spawn

Functions

Inherited Entity Functions
Base Entityscripting-reference/classes/base-classes/Entity
ReturnsNameDescription
integerGetIDGets the universal network ID of this Entity (same on both client and server)
tableGetClassGets the class of this entity
booleanIsARecursively checks if this entity is inherited from a Class
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
SetValueSets a Value in this Entity
anyGetValueGets a Value stored on this Entity at the given key
DestroyDestroys this Entity
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
ReturnsNameDescription
SetVisibilitySets the visibility in screen
WidgetVisibilityGetVisibilityReturns the current WebUI visibility
SetFocusEnables the focus on this Widget (i.e. can receive Keyboard input and will trigger input events)
BringToFrontPuts this Widget in the front of all WebUIs and Widgets
AddToViewportAdds it to the game's viewport and fills the entire screen
AddChildAdds a new child widget to this Widget container, if this is a Panel
SetContentForSlotSets the widget for a given slot by name, if this is a UserWidget
SetCanvasLayoutSets the Layout as Canvas on Screen
anyCallBlueprintEventCalls a Blueprint Event or Function
functionBindBlueprintEventDispatcherAssigns and Binds a Blueprint Event Dispatcher
UnbindBlueprintEventDispatcherUnbinds a Blueprint Event Dispatcher
SetBlueprintPropertyValueSets a Blueprint Property/Variable value directly
anyGetBlueprintPropertyValueGets a Blueprint Property/Variable value

SetVisibility

Sets the visibility in screen

my_widget:SetVisibility(visibility)
TypeParameterDefaultDescription
WidgetVisibilityvisibility

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)
TypeParameterDefaultDescription
WebUI or Widgetother

SetContentForSlot

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

my_widget:SetContentForSlot(slot_name, widget)
TypeParameterDefaultDescription
stringslot_name
Widget or nilwidgetPass it nil to remove it

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?)
TypeParameterDefaultDescription
Vector2Dscreen_location/offset_left_top?Vector(0, 0)
Vector2Dsize/offset_right_bottom?Vector(0, 0)
Vector2Danchors_min?Vector(0, 0)
Vector2Danchors_max?Vector(1, 1)
Vector2Dalignment?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...?)
TypeParameterDefaultDescription
stringevent_nameEvent or Function name
anyarguments...?nilSequence 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)
TypeParameterDefaultDescription
stringdispatcher_nameEvent Dispatcher name
functioncallbackCallback function to call (the first argument is the blueprint itself)

UnbindBlueprintEventDispatcher

Unbinds a Blueprint Event Dispatcher

my_widget:UnbindBlueprintEventDispatcher(dispatcher_name, callback?)
TypeParameterDefaultDescription
stringdispatcher_nameEvent Dispatcher name
functioncallback?Optional callback to unbind

SetBlueprintPropertyValue

Sets a Blueprint Property/Variable value directly

my_widget:SetBlueprintPropertyValue(property_name, value)
TypeParameterDefaultDescription
stringproperty_name
anyvalue

GetBlueprintPropertyValue

Gets a Blueprint Property/Variable value

— Returns any (the value).

local ret = my_widget:GetBlueprintPropertyValue(property_name)
TypeParameterDefaultDescription
stringproperty_name

Events

Inherited Entity Events
Base Entityscripting-reference/classes/base-classes/Entity
NameDescription
SpawnTriggered when an Entity is spawned/created
DestroyTriggered when an Entity is destroyed
ValueChangeTriggered when an Entity has a value changed with :SetValue()
ClassRegisterTriggered when a new Class is registered with the Inheriting System
NameDescription

✅ NativeWidgets to Unreal Widgets Relation

List of the relation Unreal native WidgetsNativeWidget 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.