Making my own AutomaticCanvasSize?

Update with more information:

The title says most of it, I need to have my own version of Automatic Canvas Size for a scrolling gui, as the listings of a gui are added by a script, not hardcoded.


This is what I have as a template, the object is inside of a scrolling gui, set to the minimum amount, so it can scale if need be.

But when the game runs, automatic canvas size doesnt work since they arent hardcoded, so it ends up looking like this & I cant scroll it:

What’s the math here? Thanks!

1 Like

If you’re using a UIListLayout, automatic canvas size should work here (if it’s set to XY or just Y), otherwise, I would add up all the frame’s Y scale/offset (depending on which one you’re using) and add the spacing (Padding). Not sure if this is what you’re looking for, but hopefully it will help with your issue :slightly_smiling_face:

I’m using autocanvas XY, I could use just Y but I’m just using XY for whatever reason. The issue is that automatic canvas size isnt scaling automatically when new guis are added to the scrollingframe.

*I’m not using a UIListLayout

What are the properties of your ScrollingFrame?

image

Try making the CanvasSize {0, 0}, {1, 0}. If this doesn’t work then you have a different problem.

I tried that, it didnt work.

Here’s the code:


image

You need to add the size and the padding to the script and it should work but you should try manually adjusting the canvas size first to make sure that the system would work.

Since AutomaticCanvasSize wasnt working, I just did it manually with some math.

I’d like to bump this with some more information, since I’m still encountering issues.

The equation shown in the above post doesnt work, it, for whatever reason, gets offset over time, & makes the canvas way larger than it should be. AutomaticCanvasSize should be doing this for me but for whatever reason its not automatically expanding when I add new items to it.

These are all of the properties relating to the issue:
image
Every gui in this game are sized using scale, the items are added after the game launches using the following code:

local Player = game.Players.LocalPlayer
local AttributionsModule = require(game.ReplicatedStorage:WaitForChild("Resources"):WaitForChild("Data"):WaitForChild("Attributions"))
local AttributionsTemplate =  Player:WaitForChild("PlayerGui"):WaitForChild("MainHud"):WaitForChild("AttributionsFrame"):WaitForChild("AttributionsFrame")

local OriginalTemplate = AttributionsTemplate:WaitForChild("Attribution")

local AttributionSpacing = (OriginalTemplate.Size.Y.Scale + OriginalTemplate.Position.Y.Scale)
local Iteration = 0

for Index,Data in pairs(AttributionsModule.Items) do
	local AttributionClone = OriginalTemplate:Clone()
	AttributionClone.Parent = AttributionsTemplate
	AttributionClone.Position = UDim2.new(.02,0,(AttributionSpacing * Iteration),0)
	AttributionClone.Creator_Name_Label.Text = Data.Creator_Name
	AttributionClone.Platform_Name_Label.Text = ("of  "..Data.Creator_Platform)
	AttributionClone.Attribution_Description.Text = Data.Contribution_Description
	AttributionClone.Link_Text.Text = Data.Link
	Iteration += 1
end

AttributionsTemplate.CanvasSize = UDim2.new(0,0,(AttributionSpacing * (Iteration - 1)),0) --This is the line that is messing up, the sizing isnt correct, & it makes a bunch of extra space at the bottom.
OriginalTemplate.Parent = nil

The thing that confuses me is that while the size of the canvas is way too large, all of the items inside the ScrollingFrame are using the same equation, just without Iteration - 1.

This is the final product of this code running:

What’s the math here, or why isnt AutomaticCanvasSize working?

Is your GUI’s size based on scale or offset?

It’s based on scale, as you can see inside of the code.

I was referring to the “AttributionClone”.

It uses scale, as shown here:
image

I just remembered I made a custom chat system a while back and had the same exact issue, except it cut off from the bottom instead of giving extra space.

Though the way I fixed it was using AutomaticCanvasSize. Is there anything else inside of the AttributionsFrame that is GUI related?

Nope, just the attribution.
image

Does changing the SizeConstraint of the Attribution do anything?

I’ve tried, dont get any changes.

Try changing your padding of the GUI to offset instead of scale.

As in position?

textextextextext