September 20, 2022


UI:CreateGUIWindow(layoutPath, instanceName)
  • Function class:UI
  • Call restrictions:Client


Create a GUI instance according to the layout path and return. The created instance will not be automatically displayed on the screen. If it needs to be displayed, the developer should manually add the instance asUI.RootDirect or indirect sub levels.


Variable name Type Describe
layoutPath string Path to the layout file of the interface
instanceName string The name of the GUI instance. By default, the layout file name is used

Return value

Type Describe
Window Window instance

Code example

Create a new interface in the interface editor


Create an instance on the client. It is recommended that when creating a window, you should consider how to operate when you need to obtain the window instance in the future. Two basic schemes are recommended: one is to use variables to store the instances returned by createguiwindow; The other is to pass in the second parameter to name the instance when calling createguiwindow, so that the instance can be obtained by getguiwindow according to the instance name.

Add the instance to the UI root node and display the instance to the player. Of course, it can also be added to other instances. Some interfaces with a large number of the same instances will be handled in this way, such as the cells in the backpack.

--use local variable to storage GUI Window
local window
local function InitUI()
    window = UI:CreateGUIWindow("dwInstance")

local function OtherFunction()
    window.Visible = true
    --to do some thing
--use instanceName to storage GUI Window, but you need hold its parent
--in this template, its parent is UI.Root
local function InitUI()
    local window = UI:CreateGUIWindow("dwInstance", "myInstance")
    window.Parent = UI.Root

local function OtherFunction()
    local window = UI.Root:GetChildByName("myInstance")
    window.Visible = true
    --to do some thing