Help With CanvasSize ReEntrance Problem

Currently - as I assume many of you are doing - I am setting the canvas size to the AbsoluteContentSize of any UILayoutConstraint when it changes.

Sample code of what that would look like:

UILayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
    Frame.CanvasSize = UDim2.fromOffset(0, UILayout.AbsoluteContentSize.Y)
end)

Now this should work well and all, however, when I change the CanvasSize for some odd reason it causes the AbsoluteContentSize to update and therefore cause a infinite reentrance bug in my code (Studio catches this but it crashes in a live-game).

I was hoping that someone would have ran into this (as far as I am concerned I haven’t found something similar here on the DevForums nor on external-sources). Any solution would be great, cheers!

(Additional information that I forgot in the original post, NO none of the elements in the ScrollingFrame are dependent on the Y axis for scaling: However, the X axis is dependent and the Y axis does have a value of 1 on the scale so that the UIAspectRatioConstraint will work. I am also using a UIGridLayout with a UIAspectRatioConstraint parented to it and the CellSize set to {0.25, 0, 1, 0}).

I see two ways you can use

Use ChildAdded/ChildRemoved on the Frame as the event instead of Changed

or only set the CanvasSize after you made all the UI elements, like so:

for i,v in pairs(Table) do
local Gui = MakeGui(v) 
Gui.Parent = Frame
end
Frame.CanvasSize = UDim2.fromOffset(0, UILayout.AbsoluteContentSize.Y)

I use the 2nd option in my game.

The issue with both methods is dealing with changing resolutions, I want to maintain a canvas size that updates with all my elements (as said in the post they do not use offset, they’re size is based off the width of the container!) - also not just changing resolutions but changing parent container sizes…

Oh, I see.

I don’t understand exactly but I maintain the resolution of my UI by doing something like this:

https://gyazo.com/8d702538802374846af70a1d4f6b7997

Scroller is a ScrollingFrame
MaintainSize is a regular frame

MaintainSize always matches the AbsoluteSize of the ScrollingFrame