Widget
/// 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​
-- Spawning a custom UserWidget Blueprint
local menu = Widget("/Game/UI/WBP_MainMenu.WBP_MainMenu_C")
menu:AddToViewport()
| Name | Type | Default | Description |
|---|---|---|---|
BlueprintPath | string | (0,0,0) | A custom UserWidget Blueprint to spawn |
NativeWidget Constructor​
-- 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)
| Name | Type | Default | Description |
|---|---|---|---|
NativeWidget | enum | NativeWidget.VerticalBox | A 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 value | Unreal Class | Panel? |
|---|---|---|
NativeWidget.Border | UBorder | âś… |
NativeWidget.Button | UButton | âś… |
NativeWidget.CheckBox | UCheckBox | âś… |
NativeWidget.Image | UImage | ❌ |
NativeWidget.ProgressBar | UProgressBar | ❌ |
NativeWidget.RichTextBlock | URichTextBlock | ❌ |
NativeWidget.Slider | USlider | ❌ |
NativeWidget.Text | UTextBlock | ❌ |
NativeWidget.ComboBox | UComboBoxString | ❌ |
NativeWidget.EditableText | UEditableText | ❌ |
NativeWidget.EditableTextMultiLine | UMultiLineEditableText | ❌ |
NativeWidget.SpinBox | USpinBox | ❌ |
NativeWidget.TextBox | UEditableTextBox | ❌ |
NativeWidget.TextBoxMultiLine | UMultiLineEditableTextBox | ❌ |
NativeWidget.CanvasPanel | UCanvasPanel | âś… |
NativeWidget.GridPanel | UGridPanel | âś… |
NativeWidget.HorizontalBox | UHorizontalBox | âś… |
NativeWidget.Overlay | UOverlay | âś… |
NativeWidget.ScaleBox | UScaleBox | âś… |
NativeWidget.ScrollBox | UScrollBox | âś… |
NativeWidget.SizeBox | USizeBox | âś… |
NativeWidget.UniformGridPanel | UUniformGridPanel | âś… |
NativeWidget.VerticalBox | UVerticalBox | âś… |
NativeWidget.WrapBox | UWrapBox | âś… |
NativeWidget.BackgroundBlur | UBackgroundBlur | âś… |