GuiService:GetGuiInset() returns '0, 0, 0, 0' for the first frame of the game with new topbar UI

I encountered a race condition when running the studio emulator where GuiService:GetGuiInset() sometimes returns Vector2.zero, Vector2.zero

Repo (LocalScript to place in StarterPlayerScripts):

local GuiService = game:GetService("GuiService")
local RunService = game:GetService("RunService")
print(GuiService:GetGuiInset()) -- 0, 0, 0, 0
RunService.Heartbeat:Wait()
print(GuiService:GetGuiInset()) -- 0, 58, 0, 0

So far I’ve only encountered this in the emulator, and only 50% of the time (indicating a race condition with core scripts), but it breaks part of my game’s UI as the entire UI tree initializes with the assumption that the topbar is 0 pixels tall.

This is only happening when the new topbar (58 pixel height) UI is visible
image

I only noticed this starting happening today; it was working fine before on the new topbar UI.

I added this block of code before my UI initializes as a workaround:

-- https://devforum.roblox.com/t/guiservicegetguiinset-returns-0-0-0-0-for-the-first-frame-of-the-game-with-new-topbar-ui/2973508
while GuiService:GetGuiInset().Y == 0 do
	RunService.Heartbeat:Wait()
end
8 Likes

To add on, this also appears to occur with the GuiService.TopbarInset property.

1 Like

pretty sure i read in the release notes for the new topbar that they intended devs to hook GuiService:GetPropertyChangedSignal("TopbarInset") for any ui that’s dependent on it, probably because the new topbar has a lot of moving parts

---game/ReplicatedFirst/LocalScript.client.lua

local GuiService = game:GetService("GuiService")

local Inset = GuiService.TopbarInset

GuiService:GetPropertyChangedSignal("TopbarInset"):Connect(function()
	Inset = GuiService.TopbarInset
	-- 0, 0, 0, 58
	-- 160, 0, 2082, 58
end)
1 Like

I added similar code to my game to get the proper padding for my UI, though for me it would happen 100% of the time

This is just an acknowledgment announcement!

We’ve filed a ticket into our internal database for this issue, and we will update you when we have further information!

Thanks for the report!

2 Likes

I’ve experienced this myself in studio in early March. I wasn’t using the new UI, so this is likely unrelated to that. I assumed it was because I was using faster play solo, but who knows.

This was my solution:
image

Hi @DataBrain your workaround is correct in that there is no change signal that will fire for GuiInset. The inset isn’t guaranteed to be constant so for now you will have to poll for value changes every frame.

As @lolmanurfunny mentioned, TopbarInset does have property changed signals, but this actually isn’t the inset of the top bar, its the rect of the safe area of the top bar.

I will talk to the team to see if if it might be possible to offer a changed signal for the insets! If you’d like to create a specific ticket for tracking the request, please go to the Feature Requests section of the forum:

Thanks!