AutomaticCanvasSize does not work

The AutomaticCanvasSize does not seem to actually work.

I had to write a script that changes the canvas size based on the number of frames.

The script does work, but it is always a little off when the number of frames changes.

Here is that script:


local ScrollingFrame = script.Parent:WaitForChild("ScrollingFrame")


function GetFrames()
	local Count = 0

	for i, v in ipairs(ScrollingFrame:GetChildren()) do
		if v:IsA("Frame") then
			Count += 1
		end
	end

	return Count
end

local TotalFrames = GetFrames()

ScrollingFrame.CanvasSize = UDim2.new(TotalFrames * .2676, 0, 0, 0)

print("ScrollingFrame.CanvasSize.X =", ScrollingFrame.CanvasSize.X)

Here is the test file if you want to look at the settings.

ScrollingFrame.rbxl (63.9 KB)

5 Likes

No need of script, use AutomaticCanvasSize set it to x.

2 Likes

In order for AutomaticCanvasSize to work properly, you must also set the CanvasSize property of the ScrollingFrame to {0, 0}, {0, 0}. This is because if you have a pre-determined CanvasSize, it can’t automatically re-size it, as it already has a pre-determined size. If the size is not pre-determined ({0, 0},{0, 0}) then it can re-size appropriately.

There isn’t really a good explanation for it, its kind of just how Roblox GUI elements work.

1 Like

The file I uploaded has the CanvasSize set to Zero.

I had already tried using AutomaticCanvasSize with the CanvasSize set to zero.

It did not work.

1 Like

Inside of the UIListLayout under the ScrollingFrame, change the FillDirection property to Vertical and set the Wraps property to True.

image

Also, you will need to remove the UIAspectRatioConstraint from the ScrollingFrame.

I tried your suggestions but they did not work.

I also do not see a wrap option for UIListLayout

Screen Shot 2024-03-23 at 5.07.41 PM

Or for UIGridLayout

I didn’t see it as an option on the ScrollingFrame either.

Screen Shot 2024-03-23 at 5.10.51 PM

Also, I prefer to keep the UIAspectRationConstraint if possible. But, I did try deleting it to see if it was the problem. It did not work then either.

I also noticed that unless I set a CanvasWidth (either with a script, or manually in the Properties window), there will not be a scroll bar at all.

1 Like

Did you download the file I posted?

I made it available because I knew this was a tricky problem.

1 Like

I did download the file and it gave me those options. I don’t know why you don’t have them. I can’t think of any other solutions right now but I will let you know if I do.

Have you tried updating Studio?

Studio updates automatically. (All the time :grinning:)

Thanks for looking into it.

I also cannot find a solution.

1 Like

When I set the UIListLayout direction to Vertical and wrap to True, delete the UIAspectRatioConstraint, and set AutomaticCanvasSize to XY in the ScrollingFrame, this is what I am able to do:

1 Like

When you add a bunch more frames does it continue to scale correctly?

1 Like

Can you send me a screenshot of the Properties window with the Wrap option visible?

Maybe I am blind?

1 Like

Yes. Using a set up like this I can keep everything scaled like you want it.

image

When adding several more frames this is the result:

Here is the properties window of the UIListLayout:

image

Thank you for solving the problem.

You clearly have.

I don’t understand why I don’t have the same Properties:

I am on a Mac, not a Windows computer. Maybe that is the difference.

1 Like

That might be the reason. It is also possible that it’s a beta feature. I think I have beta features enabled in Studio.

I will try to look for a solution around this!

I went to Beta and read through them, there it is!

Now I have the option:

Thanks so much for all your time and help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.