.
Basically, every Element is an expandable element and the list of elements is dynamic. I need my red RectTransform size to be dynamic because I want to be able to scroll vertically.
I managed to make it work but Unity is warning me about the ContentSizeFitter that is attached to the Cyan gameobject telling me : “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.”.
So am I doing something wrong ? Should my UI be designed in another way ?
I really need those 2 Content Size Fitter components, otherwise the RectTransform size is not dynamic and I will not be able to scroll correctly.
I would also love to know. Especially, because the same issue is present when following the Scrolling menus at runtime tutorial on the Unity web page around 12:25. The tutorial is relatively new, and Unity did not display a warning there. Now it does. Question is, how should we do it instead. In the tutorial he mentions writing a script that calculates the size. But this seems to be what content size fitter is already doing. Recreating an existing class, does not seem particularly useful. Any ideas?
@Chichkan thank you for trying to help. Unfortunately the page of the manual does not adress this particular issue, but it is helpful with regards to content size fitter anyways
The problem seems to be that Unity sees the Scroll Rect script as a Layout group. I am not sure why as the documentation states it inherits from UIBehavior. What I ended up doing is putting the scroll rect script on the content panel itself and set the Viewport to the parent view that masks the list. This works and does not give a warning.
If the problem is the warning message of Content Size Fitter on the panel with scrolling content, I think it’s because one of the parents of your ScrollRect contains a LayoutGroup. If you don’t want to see this warning, try to make the following hierarchy:
ScrollRect
— Viewport (with Mask and Image)
------ Content (with Content Size Fitter and Vertical Layout Group)
At least this is how new Unity 5.2.2 creates standart ScrollRect UI element and there is no warning messages.
wtf… this is counter intuitive, most of the time you will want a scroll rect game object to be parent of a game object with a content size fitter since you never know what it’s going to be the size of the content rect… I just nested the game object with content size fitter into an empty game object and nested this empty game object into the scroll rect game objct and that worked, but this makes totally no sense.
yeh, i don’t think it should show this warning, however, the warning doesn’t result in any buggy behavior (as far as i’ve tested), so i think you can keep the scroll rect without problems.
I guess the problem is that if you force expand vertically in the vertical layout group while at the same time trying to fit vertically in the content size fitter too then you have a conflict. There doesn’t seem to be one if layout group is not set to touch the same direction as the content size fitter. Still it’s not nice to see a warning:(
Well… but this is what you need to do for scrollrect ro work. It is even shown in the official unity tutorial video… but the video doesnt show the warning.
Exactly my point actually. I wasted 2 hours yesterday trying to get a simple chat box working - read this HOWTO and tried following it: https://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html
Still those warnings kept showing up and I thought it was me doing something wrong.
The warning system really ought to be a little more intelligent and only show a warning if there is an actual conflict, instead of the general one.
A little more googling sent me to this thread.
Most of the time Unity is a really nice engine but sometimes you just want to pull your hair out because it forces you to jump through hoops of peculiar and scarcely documented behaviour.
I do give kudos to the guys at unity for trying hard. I am sure they are doing as best as they can but i cant get over this feeling that they are being a bit over run and stretched thin most of the time from sheer amount of support needs.
Yup and QA is definitely being responsive also I filed a bug report on a problem I had with dynamically adding text to a vertical layout group and also mentioned the problem with the warning. They merged it with the following issue, and confirmed to me that the warning problem is also included in the issue now:
Finally solved this after…way too much time. There’s a pretty painless solution - although it was NOT obvious and took a lot stabbing around in the dark. My problem was similar to the original post. I’m creating an app where there are Questions posted, and every question will have a variable number of answers displayed underneath. (I know there aren’t going to be an insane number of answers for each question, so I want all of the questions and answers to be visible, and I want all of it to be scrollable.) Every question will have a different number of answers, so it’s important that every Q/A parent object have its own perfectly fitted rect transform size, so that the spacing between each Q&A cluster is consistent. Here’s what I eventually did to make sure each q/a cluster is dynamically fitted, no matter how many or few answers 1.) Create new UnityUI ScrollView. 2.) DropDown the arrow for Viewport, and delete “Content” object underneath of it; then replace it with a holder object that you want to contain everything that is scrollable (I named mine “AllQuestionsAllAnswers”). 3.) AllQuestionsAndAllAnswers has a ContentSizeFitter component and a vertical layout group component. 4.) As a child of AllQuestionAndAllAnswers I have several prefabs representing individual Q&AClusters (I call these objects PromptAndContent). Each PromptAndContent object has a vertical layout group, and content size fitter component attached. On the vertical layout component, I need to use child force expand for both height and width to get a nice consistent spacing between Q&A block. For the Content Size fitter, in the Vertical Fit dropdown, I have to use Preferred Size. (This makes all the difference. Before I was using Min Size and I would get the error discussed above, and it would not work at all.) Now, after using Preferred Size, I still see the warning, but when I add new Answer prefabs dynamically, as children under PromptAndContent, I see that the bounding box for PromptAndContent object adjusts to fit all answers perfectly. Let me know if it works for you.