Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ScrollView with Horizontal Layout Group

Discussion in 'UGUI & TextMesh Pro' started by nventimiglia, Aug 21, 2014.

  1. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    I would like to add objects to the scroll content view at runtime and use the grid to space the objects out. I am unable to creating a working prototype using uGUI. Use of any layout control seems to break the Scroll View and its content.

    Steps to replicate
    • Open the demo project and open the ScrollView scene
    • Expand the Canvas/Window/Content/ScrollView/Content
    • Attach a HorizontalLayoutGrid to the child most content element
    • Set a logical spacing, I chose 200
    • At design time, the grid works correctly, the objects are spaced
    • Play
    • At runtime the child objects all rest to the corner with a position of 0,0

    More Notes
    • If I disable the Horizontal Layout Grid, the children do not reset their position on play.
    • If I remove / add objects to the container the size of the container does not change
    • The size of the container should reflect its children
    • If I disable then reenable the Layout Grid, it works.
     
    Last edited: Aug 21, 2014
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Hi, this should work properly. Could you raise a bug so we could see exactly what you are doing in code?
     
  3. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    I have submitted the project using the Bug Reporter.

    The Bug Reporter did not give me a Ticket #.
    I put this down as "problem with player"
    I referenced this topic in the help request.
     
  4. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    (Case 627639) uGUI BETA
     
  5. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    See if this helps, just created a simple project with a ScrollRect, Mask, ContentSizeFitter and HorizontalLayout Group.
    Also added a button that will programatically add new children to the LayoutGroup which resizes appropriately.

    Hoe this helps, if I missed anything from what you were asking, please let me know.
     

    Attached Files:

    TechSupportIncoming1 likes this.
  6. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    This does help. I did not even know about the fitter or the layout element scripts. That said, I still have some problems.

    • Items are placed outside of the scroll area. If you disable the mask it is quite obvious the first item is added 1/2 way outside the scroll;
    • The scroll position moves. I tried caching the scroll value and reapplying it after I add the prefab. That did not work, so I put it in a coroutine with a yield statement, that did not work. Then I tried waiting 10 frames... it works but is ugly.