Ir para o conteúdo principal
Version: latest - a1.65.x ⚖️

🪟 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.
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

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

📚 Libraries & Frameworks

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

🛠 Constructors

UserWidget Constructor

local my_widget = Widget(blueprint_path)
TypeNameDefaultDescription
Blueprint Referenceblueprint_path Required parameter A custom UserWidget Blueprint to spawn

Native Widget Constructor

local my_widget = Widget(native_widget)
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
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
DestroyDestroys this Entity
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
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
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
SetCanvasLayoutSets the Layout as Canvas on Screen
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)
SetVisibilitySets the visibility in screen
Widget3DSpawnWidget3DSpawns a 3D Widget actor rendering this Widget in the world
UnbindBlueprintEventDispatcherUnbinds a Blueprint Event Dispatcher

AddChild

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

my_widget:AddChild(other)
TypeParameterDefaultDescription
WebUI or Widgetother Required parameter No description provided

AddToViewport

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

my_widget:AddToViewport()

BindBlueprintEventDispatcher

Assigns and Binds a Blueprint Event Dispatcher

— Returns function (the callback itself).

local ret = my_widget:BindBlueprintEventDispatcher(dispatcher_name, callback)
TypeParameterDefaultDescription
stringdispatcher_name Required parameter Event Dispatcher name
functioncallback Required parameter Callback function to call with this format

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

CallBlueprintEvent

Calls a Blueprint Event or Function
Returns all Function return values on Client Side

— Returns varargs of any (the function return values).

local ret_01, ret_02, ... = my_widget:CallBlueprintEvent(event_name, arguments...?)
TypeParameterDefaultDescription
stringevent_name Required parameter Event or Function name
anyarguments...?nilSequence of arguments to pass to the event

GetBlueprintPropertyValue

Gets a Blueprint Property/Variable value

— Returns any (the value).

local ret = my_widget:GetBlueprintPropertyValue(property_name)
TypeParameterDefaultDescription
stringproperty_name Required parameter No description provided

See also SetBlueprintPropertyValue.


GetVisibility

Returns the current WebUI visibility

— Returns WidgetVisibility.

local ret = my_widget:GetVisibility()

See also SetVisibility.


SetBlueprintPropertyValue

Sets a Blueprint Property/Variable value directly

my_widget:SetBlueprintPropertyValue(property_name, value)
TypeParameterDefaultDescription
stringproperty_name Required parameter No description provided
anyvalue Required parameter No description provided

See also GetBlueprintPropertyValue.


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)No description provided
Vector2Dsize/offset_right_bottom?Vector(0, 0)No description provided
Vector2Danchors_min?Vector(0, 0)No description provided
Vector2Danchors_max?Vector(1, 1)No description provided
Vector2Dalignment?Vector(0.5, 0.5)No description provided

SetContentForSlot

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

my_widget:SetContentForSlot(slot_name, widget)
TypeParameterDefaultDescription
stringslot_name Required parameter No description provided
Widget or nilwidget Required parameter Pass it nil to remove it

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

SetVisibility

Sets the visibility in screen

my_widget:SetVisibility(visibility)
TypeParameterDefaultDescription
WidgetVisibilityvisibility Required parameter No description provided

See also GetVisibility.


SpawnWidget3D

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

— Returns Widget3D.

local ret = my_widget:SpawnWidget3D(location?, rotation?, widget_space?, auto_size?, size?, auto_repaint_rate?, pivot?)
TypeParameterDefaultDescription
Vectorlocation?Vector(0, 0, 0)No description provided
Rotatorrotation?Rotator(0, 0, 0)No description provided
WidgetSpacewidget_space?WidgetSpace.WorldNo description provided
boolauto_size?falseNo description provided
Vector2Dsize?Vector2D(500, 500)Only works if auto_size = false
floatauto_repaint_rate?-1Leaves -1 to repaint every frame
Vector2Dpivot?Vector2D(0.5, 0.5)No description provided

UnbindBlueprintEventDispatcher

Unbinds a Blueprint Event Dispatcher

my_widget:UnbindBlueprintEventDispatcher(dispatcher_name, callback?)
TypeParameterDefaultDescription
stringdispatcher_name Required parameter Event Dispatcher name
functioncallback? Required parameter 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 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.