Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Layout Group and ContentSizeFitter in child

Discussion in 'Unity UI & TextMesh Pro' started by kenny_cj, Jul 23, 2015.

  1. kenny_cj

    kenny_cj

    Joined:
    Feb 12, 2015
    Posts:
    3
    Hey everyone !

    So, Here is a graph of my UI :
    UIGraph.png .
    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.

    Thanks for your input / advice.
     
    EvilTak and rakkarage like this.
  2. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    144
    We see exactly the same. Any advice would be great
     
  3. espresso

    espresso

    Joined:
    Nov 21, 2012
    Posts:
    1
    Same here, it seems to work fine but the warning makes me think I'm doing something wrong?

    In my case the size fitter is on the same object as the vertical layout group so there isn't even one on the 'parent'.
     
    rakkarage likes this.
  4. w4der

    w4der

    Joined:
    Sep 17, 2011
    Posts:
    9
    Hi,
    Did you solve the problem?
    I would be grateful if you will explain how you fix this ;)
    Best Regards,
    W4der
     
  5. baerbel

    baerbel

    Joined:
    Feb 24, 2015
    Posts:
    3
    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?
     
  6. Chichkan

    Chichkan

    Joined:
    Jun 15, 2015
    Posts:
    4
  7. baerbel

    baerbel

    Joined:
    Feb 24, 2015
    Posts:
    3
    @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.
     
  8. Chichkan

    Chichkan

    Joined:
    Jun 15, 2015
    Posts:
    4
    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.
     
  9. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    56
    i had a similar problem where i had
    Parent with scroll rect, Mask & Image
    - child with horizontalLayout & content fitter
    --sub-children with layout element

    i found that it is caused by the scroll rect in the parent (the warning disappears if you remove it).
     
  10. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,054
    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.
     
  11. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    56
    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.
     
  12. chilton

    chilton

    Joined:
    May 6, 2008
    Posts:
    449
    Holy cow this is still happening. Oh sure I can get around it by nesting a game object between the layers, but that's a pretty hacky solution.
     
  13. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,233
    Yeap, this is still happening in 5.5
     
    Jesper-Nielsen likes this.
  14. Jesper-Nielsen

    Jesper-Nielsen

    Joined:
    Nov 14, 2013
    Posts:
    41
    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:(
     
  15. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,233
    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.
     
    Jesper-Nielsen likes this.
  16. Jesper-Nielsen

    Jesper-Nielsen

    Joined:
    Nov 14, 2013
    Posts:
    41
    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.
     
  17. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,233
    Yeah i agree.

    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.
     
    Jesper-Nielsen likes this.
  18. Jesper-Nielsen

    Jesper-Nielsen

    Joined:
    Nov 14, 2013
    Posts:
    41
  19. taylorjamess91

    taylorjamess91

    Joined:
    Jul 30, 2017
    Posts:
    1
    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.


    prefSize.png
     
  20. TharosTheDragon

    TharosTheDragon

    Joined:
    Sep 2, 2017
    Posts:
    13
    So the warning is just another Unity bug?
     
  21. iamkomal

    iamkomal

    Joined:
    Jan 15, 2014
    Posts:
    1
    I have already done with these steps still I am able to scroll text forever. However, my text element is child of last component i.e. sub children with layout element.
    May you help me out with this.