Skip to main content

Widget

The **Widget** class lets Lua scripts spawn **User Widgets** (Blueprint classes) or **native Unreal Widgets** and then manipulate them exactly as you would in Blueprints. It is the building‑block for creating 2‑D user interfaces in‑game.

/// tip Widget inherits every method and event from Entity. ///

/// tip Most widget‑specific functions are not exposed directly as Lua methods. Use CallBlueprintEvent() to invoke any function or event on the underlying UWidget / UUserWidget. ///

Constructor​

UserWidget Constructor​

Example
-- Spawning a custom UserWidget Blueprint
local menu = Widget("/Game/UI/WBP_MainMenu.WBP_MainMenu_C")
menu:AddToViewport()
NameTypeDefaultDescription
BlueprintPathstring(0,0,0)A custom UserWidget Blueprint to spawn

NativeWidget Constructor​

Example
-- Creating a VerticalBox with a Text and a Button
local vbox = Widget(NativeWidget.VerticalBox)
vbox:AddToViewport()

local txt = Widget(NativeWidget.Text)
txt:CallBlueprintEvent("SetText", "Hello World!")

local btn = Widget(NativeWidget.Button)

vbox:AddChild(txt)
vbox:AddChild(btn)
NameTypeDefaultDescription
NativeWidgetenumNativeWidget.VerticalBoxA native Unreal Widget to spawn

Functions​

SetVisibility​

Sets the visibility of the widget on screen

  • visibility: number - 0 Hidden, 1 Visible, 2 VisibleNotHitTestable
my_widget:SetVisibility(0)

GetVisibility​

Returns the current visibility state

  • returns: ESlateVisibility
local isVisible = my_widget:GetVisibility()

SetFocus​

Gives keyboard / game‑pad focus to this widget

my_widget:SetFocus()

BringToFront​

Moves this widget to the top‑most Z‑order

my_widget:BringToFront()

AddToViewport​

Adds the widget to the game viewport and stretches it full‑screen

my_widget:AddToViewport()

AddChild​

Adds another widget as a child, if parent widget is a Panel

  • widget: enum
local child = Widget(NativeWidget.Text)
parent:AddChild(child)

SetContentForSlot​

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

  • name: string
  • widget: UWidget
my_widget:SetContentForSlot("InventorySlot", some_other_widget)

SetCanvasLayout​

Sets anchors / position / size when the widget is a child of a CanvasPanel

  • position: Vector2D
  • size: Vector2D
my_widget:SetCanvasLayout(Vector2D(50,50), Vector2D(200,100))

CallBlueprintEvent​

Calls any Blueprint function or event on the underlying widget and returns its results

  • widget: enum
local my_text = Widget(NativeWidget.Text)
my_text:CallBlueprintEvent("SetText", "Hello World!")

BindBlueprintEventDispatcher​

Binds a Blueprint dispatcher and returns the Lua callback reference

my_button:BindBlueprintEventDispatcher("OnClicked", function()
print("Button clicked!")
end)

UnbindBlueprintEventDispatcher​

Unbinds a previously bound dispatcher

my_button:UnbindBlueprintEventDispatcher("OnClicked", cb)

SetBlueprintPropertyValue​

Sets a Blueprint variable directly

my_widget:SetBlueprintPropertyValue("bIsEnabled", false)

GetBlueprintPropertyValue​

Gets a Blueprint variable value

local enabled = my_widget:GetBlueprintPropertyValue("bIsEnabled")

NativeWidget ↔ Unreal Widget map​

Enum valueUnreal ClassPanel?
NativeWidget.BorderUBorderâś…
NativeWidget.ButtonUButtonâś…
NativeWidget.CheckBoxUCheckBoxâś…
NativeWidget.ImageUImage❌
NativeWidget.ProgressBarUProgressBar❌
NativeWidget.RichTextBlockURichTextBlock❌
NativeWidget.SliderUSlider❌
NativeWidget.TextUTextBlock❌
NativeWidget.ComboBoxUComboBoxString❌
NativeWidget.EditableTextUEditableText❌
NativeWidget.EditableTextMultiLineUMultiLineEditableText❌
NativeWidget.SpinBoxUSpinBox❌
NativeWidget.TextBoxUEditableTextBox❌
NativeWidget.TextBoxMultiLineUMultiLineEditableTextBox❌
NativeWidget.CanvasPanelUCanvasPanelâś…
NativeWidget.GridPanelUGridPanelâś…
NativeWidget.HorizontalBoxUHorizontalBoxâś…
NativeWidget.OverlayUOverlayâś…
NativeWidget.ScaleBoxUScaleBoxâś…
NativeWidget.ScrollBoxUScrollBoxâś…
NativeWidget.SizeBoxUSizeBoxâś…
NativeWidget.UniformGridPanelUUniformGridPanelâś…
NativeWidget.VerticalBoxUVerticalBoxâś…
NativeWidget.WrapBoxUWrapBoxâś…
NativeWidget.BackgroundBlurUBackgroundBlurâś…
✨