I’m adding a widget to a Canvas with a SizeBox as the root.
However, I noticed that when I added the widget I created using AddChildToCanvas, the root widget was strangely stretched horizontally.
To be precise, the visual will be displayed according to the size box, but the bounce will not be affected, resulting in unintended gaps.
SizeToContent Is not checked, and no other size override process.
Also, if i place it in advance or add it to a VerticalBox etc, it will be displayed correctly.
To avoid this issue, i need to execute SetSize as a CanvasPanelSlotObject after adding it to the Canvas. This is very tedious…
Why does this happen? Is AddChildToCanvas silently overriding the root size?
Yes & no . You’d need to Size To Content, then the canvas will () respect the child’s Desired Size which the Size Box dictates via overrides. You probably know this already, the canvas slot becomes available as soon as the widget is added to the container:
I tried SizeToContent but that didn’t solve the problem. No matter what I did the widgets were stretched or had weird gaps.
But somehow SetAutoSize worked. Probably has the same effect as SetSize.
Anyway, Now it’s working as expected.
I don’t know the exact reason, but thank you for your help.