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

Scale problem when adding items script

Discussion in 'UGUI & TextMesh Pro' started by -JohnMore-, Oct 15, 2014.

  1. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64
    Hi,

    I have a weird problem and don't know if it is a bug. Chances are I am doing something wrong.

    I have a ScrollRect with a Grid for the items. The content gameobject has the GridLayout component and a ContentSizeFitter so it can grow if needed. Inside I have 5 test prefabs to test the layout. Everything works great.

    ScaleProblemEditor.jpg

    But the, I run the proyect, I delete all the prefabs and add new ones from saved data. The prefab is the same and it does not modify its size. I expected it to mantain the layout I created for them but sadly it does not work.

    ScaleProblemRuntime.jpg

    When I check the instantiated prefab scale, in the editor it is x:1 y:1 z:1, while at runtime it is x:1.643836 y:1.643836 z:1.643836. If I manually change their scale everything works ok again.

    Thanks.
     
  2. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Is it a Screen Space - Camera Canvas style by chance?

    Just ran into this same problem, I'd say report it~
     
  3. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64
    In my case it's Screen Space - Overlay, but I'd say it the same bug. By the way, are you having a problem where you have child gameobjects visible even when the parent is disabled? Just asking.
     
  4. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    @JohnMore post the code how you instantiated the prefab. Maybe i can help then i had similar issues.
     
  5. FamerJoe

    FamerJoe

    Joined:
    Dec 21, 2013
    Posts:
    193
    I have a similar problem instantiating prefab Text elements in a char ScrollRect. I don't know if it's the case in your case, but it started happening when I added Canvas Scaler to my root UI. It seems it's performing some sort of scale on my prefabs at the time of Instantiation.

    I did a little investigation: I have my canvas scaler set to 1920 x 1080. When I start the game up in that resolution, the instantiated text elements spawn fine with a scale of 1. When I start it up @ 960x540 (half res) the scale is 2, so it appears twice as big as it should. The fix is setting the scale to 1 post instantiate.
     
  6. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64

    It seems this is my problem. I fixed this the same way you did but did not know why it happened. Thanks!
     
  7. FamerJoe

    FamerJoe

    Joined:
    Dec 21, 2013
    Posts:
    193
    No problem!
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,877