- Home /
Warning when combining content size fitter and vertical layout group
I followed the Unity tutorial on Scrolling menus at runtime. It works quite well. However I see a warning, when adding a Content Size Fitter to the scroll panel, which already has a layout group. (In the video that happens around 12:25 and does not merit a warning).
Parent has a type of layout group component. A child of a layout group should not have a Content Size Fitter component, since it should be driven by the layout group.
The warning would make sense to me, if I had the Content Size Fitter on the children of the scroll panel. But the scroll panels size should not be changed by its Layout group at all, or should it?
Is there a better way to achieve a scroll view in newer versions of Unity or is the warning just appearing in the wrong place?
Answer by Black_Demon · Apr 19, 2017 at 10:00 AM
Although this post is quite old, if someone is looking for the solution, it was answered here
Answer by phil_me_up · Feb 16, 2016 at 01:35 PM
You should set this up with the Content Size Fitter component and the Vertical Layout Group component on the same object. In you're situation this would be something like
->Scroll Rect Object (with scroll rect component)
--->Scroll Container (Content Size Fitter and Vertical Layout Group components)
----->Scroll content 1 (With Layout Element component)
----->Scroll content n (With Layout Element component)
This is the heirarchy in the tutorial, and the warning described above appears in this setup. I tested it in Unity 5.3.5f1.
Answer by Ni-Donoso · Jul 17, 2019 at 03:17 AM
Hello Everyone
I had a same problem but I used this method.
content (layout & content fitter)
child layout1(layout & content fitter)
child layout2(layout & content fitter)
...
child layoutn(layout & content fitter)
Code:
int refreshCounter = 0;
void Update() {
if (refreshCounter > 0)
{
refreshCounter --;
if (refreshCounter == 0)
{
content .GetComponent<Image>().enabled = !content .GetComponent<Image>().enabled;
}
}
}
void ChildProcess() {
//add or remove elements to or from child layout1~n
...
refreshCounter = 2;
//not 1, because after next first frame, the canvas is rendered
}