Getting UI to scale to same size, irrelevant of their parents size

Looking at my X button, it’s in 2 separate frames, each frame has its own size.



Inside each X button is a UIAspectRatioConstraint With AspectType set to ScaleWithinParentSize and DominantAxis at Height. Both of them are sized to (0.75, 0, 0.75, 0)

Is there any way to get the buttons to always be the same size, irrelevant of the frames size. I DO NOT want to scale each button individually so they ‘look close enough’. I want to keep each ones size set at (0.75, 0, 0.75, 0) and then somehow using UIAspectRatioConstraint get them to appear the same size, or if there’s a way to scale them based on the screens size and not the parent size

Please note. I am NOT going to use Offset. All UI is using Scale. Using offset has never made my UI look correct on every single device scale

2 Likes

BlockquotePlease note. I am NOT going to use Offset. All UI is using Scale. Using offset has never made my UI look correct on every single device scale

What you are describing in this thread is exactly what offset is used for.
It should work perfectly for what you are asking for.

Anyways if you have the X button with scale its going to scale with the parents size which is why you are running into this.

2 Likes

Offset can’t be used properly with scaling tho. 50x50 looks massive on mobile but is near invisible on a console. That’s why ai can’t use it

1 Like

Not quite sure what you are asking then. You said:

Blockquote Is there any way to get the buttons to always be the same size, irrelevant of the frames size

Blockquote I DO NOT want to scale each button individually so they ‘look close enough’

Everything you are asking for go against eachother? do you mind rephrasing what you are looking for

Use only one UIAspectRatioConstraint in the highest frame in the hierarchy. Assuming you use scale on all the elements in there, they should all appear the same size on all devices.

I want to know if there is a way to scale them based off screen size and not their parent size. That way 0.075x0.075 is off the screen (which stays the same irrelevant of the frames size)

You can scale UI elements based on the screen size and not their parent size by using this code:

local camera = workspace.CurrentCamera

local xScale, yScale = 0.25, 0.5

local function adjustSize()
	uiElement.Size = UDim2.new(0, camera.ViewportSize.X*xScale, 0, camera.ViewportSize.Y*yScale)
end

adjustSize()
camera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
	adjustSize()
end)

You used offset. I cannot use offset at all. I don’t wanna have to constantly adjust the size of the UI whenever their screen changes. What I have currently seems real close, but still not there :confused:

return function(screen, parent)
	local Size = RoundNumber(screen.AbsoluteSize.X / 40)
	
	return UDim2.new(Size / parent.AbsoluteSize.X, 0, Size / parent.AbsoluteSize.X, 0)
end

Size is used to be the ‘Constant’ as it’s based on the players screen size, and that’s gonna be the same across all UI elements. Problem is with setting the UDim. it does set the button to different scales, but their AbsoluteSizes are still different :confused:

Can see clearly that the 2 close buttons are different sizes.

Shows that both have different AbsoluteSizes