Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why a UI GameObject size it's not the related to its child ?

Discussion in 'UGUI & TextMesh Pro' started by bali33, Aug 26, 2014.

  1. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hi guys,

    After playing a bit with UI and more specifically with scrollable content using a Scroll Rect and Layout I felt the way it's done it not logic.

    When I add a Scroll Rect component to a Panel for instance, I want all my Panel content to be part of the scrolling - and I want that behavior even if I add content dynamically.

    But there is not how it works - the scroll area is based on the height of the Scroll Rect Content property but this value is not computed dynamically and what I think it's weird it's that the height it's not related to the height of the child that the Content contains.

    It's weird for me that a Panel I want scrollable has not it's entire content scrollable if it's content is added by code. It's strange to have to add a Content Size Filter just in order to have it's size computed dynamically.

    For me UI is about 2D element, a 2D element size is its "bouding box" based on its children.

    It's not about criticize, it's about giving a feedback. I came from 2D development and I'm used to have a 2D element sized being dynamic - like in Action Script and the very well thought Feather UI framework.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    We tried to make the ScrollRect automatically encompass all children at one point but it produced a big performance hit when there were many children.
     
  3. Supergeek

    Supergeek

    Joined:
    Aug 13, 2010
    Posts:
    103
    If you just update the bounds of the ScrollRect when children are added and removed, not every tick, that shouldn't be too bad on performance should it?
     
  4. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Use ContentSizeFitter with Layout for that.
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Unfortunately that's not enough. We can't know that the children are not moving, and there's no good way to know if a transform has moved without checking. And if even just one child was moving it would mean having to recalculate the bounds (based on all children in the sub-tree) every frame for as long as it was moving.
     
  6. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    What about a method that allows to recalculate the bounds which could be called manually ? It's won't solve all cases but it will allow to add child dynamically (like adding buttons according to a local or remote save or whatever) and then call that method. It will be very usefull for developers, ok it won't solves cases where the content (children) are moving, but it will allow to initialize/update the content whenever needed and then ask for update the content bounds.