Search Unity

My Scroll View elements (prefabs one) scaling isn't right when created on a smaller window

Discussion in 'UGUI & TextMesh Pro' started by el_trex, Aug 12, 2017.

  1. el_trex

    el_trex

    Joined:
    Apr 13, 2016
    Posts:
    22
    SOLVED (see the post below) but I don't like the solution, I think Unity engine should doing the scaling automatically whitout hardcading it. So is that a bug ???
    Hi,
    I have a scroll view whose Elements are prefabs.
    The prefab is a simple gameobject containing 2 UI Buttons.
    I add them on the Content object (child of the viewport) with a vertical layout.
    This is OK.

    If launch the game in editor and prompt my panel containing the scroll view, the latter is well populated withs my prefabs instanciation.
    Then I resize the window and the panel and the scroll view elements (prefabs instantiation) are correctly resized as well. Which is logic i have a Canvas Scaler : Scale with screen size activated.

    But the issue is when I close my panel and reopen it : The prefabs are instantiate again but without taking the care of the proper scaling !

    here is a video of the issue :



    Thx for any help about this. ;)
     
    Last edited: Aug 13, 2017
  2. el_trex

    el_trex

    Joined:
    Apr 13, 2016
    Posts:
    22
    Ok so I solved this by Hardcoding the localScale of my prefab when i instanciate them to be equal of the root.localScale :
    Code (CSharp):
    1. GameObject go = Instantiate(entryPanelTemplate) as GameObject;
    2.          
    3.  
    4.             // Have to do this cause if we instantiate our Load/Save Entry element on our scroll view
    5.             // the scaling is not properly cascaded down on them ... (BUG of Unity ?)
    6.             go.transform.localScale = transform.root.localScale;
    Where entryPanelTemplate is the variable that store my prefab (corresponding to an entry of the list displayed in the scroll view).
    So this is working :


    But I think Unity engine should have properly cascaded the scale automatically, so is that a bug of Unity ???
     
    Azurne likes this.
  3. Cloaked_One

    Cloaked_One

    Joined:
    Feb 12, 2016
    Posts:
    6
    thanks for posting this. helped me out tons!