I seem to be having an issue with one of the GUIs I’m making. If I set ScreenInsets to none, the GUI will fill up the entire area of the screen like I want it to. However, I’m using the AbsoluteSize/AbsolutePosition of other GUIs to get the gui to be relative to other GUIs on the screen.
The problem I’m running into is that AbsoluteSize/AbsolutePosition assume ScreenInsets of CoreUISafeInsets. Similarly, GuiService:GetGuiInset(), returns the insets for a inset of type Enum.ScreenInsets.TopbarSafeInsets, whereas what I need is the Inset for the type Enum.ScreenInsets.None
Any idea how to get the true Enum.ScreenInsets.None GuiInset?
If anyone else needs a quick fix for this, this seems to work across all devices as far as I can tell (although it only returns the TopLeft Inset). Let me know if someone knows of an actual roblox function so I don’t have to use this janker.
local function getInset()
local sg = Instance.new("ScreenGui", Player.PlayerGui)
sg.Enabled = false
local frame = Instance.new("Frame", sg)
local sg2 = sg:Clone()
sg.SafeAreaCompatibility = Enum.SafeAreaCompatibility.FullscreenExtension
sg.ScreenInsets = Enum.ScreenInsets.None
local vect = sg2.AbsolutePosition - sg.AbsolutePosition
sg:Destroy()
sg2:Destroy()
return UDim2.new(0, vect.X, 0, vect.Y)
end
You are correct, the AbsolutePosition property uses the CoreUISafeInsets viewport coordinate system. We recently updated the docs for GuiBase2d.AbsolutePosition to add this info!
We do not currently have a lua API to get the screen inset sizes, which would be needed to convert between screen coordinate systems. However, it looks like your code for doing this should work fine!
We also have this code snippet for getting the inset sizes for a given Enum.ScreenInsets value here: link. In that snippet we reuse the test ScreenGui (without deleting it) because it can be expensive to create/destroy a ScreenGui each time you query the screen insets (depending on how often the function is called).