Search Unity

GridLayout creating elements underneath dynamically, dealing with UI scaling.

Discussion in 'UGUI & TextMesh Pro' started by hyiero, Sep 15, 2016.

  1. hyiero

    hyiero

    Joined:
    Jun 12, 2015
    Posts:
    7
    Okay just a little setup on whats going on. I have a canvas scaler set to a reference resolution of 1920x1080, and a script running on a panel that will dynamically place the amount of boxes into the gridlayout to cover the space of the panel. Taking in for account whatever padding and spacing is on the gridlayout group. The issue occurs when you start the game in 1920x1080 and scale it down to 800x600 the scaled down version is different than the ui that is started in 800x600.

    I have somewhat corrected this issue by manually setting the canvas reference resolution to the resolution the game is currently running at but that also means that arrangement of UI scaled to 1920x1080 will not line up correctly with the canvas reference set to 800x600 in game. I can completely solve the issue by also starting the game and setting the resolution to the reference resolution. Building out the guis with this resolution and then setting back to their saved resolution before rendering the start screen. But just seemed like a very hacky way to go about it.

    Couple screen shots included to kind of display the issue. Was wondering how other people deal with the issue. Or if I am doing something wrong.
     

    Attached Files:

  2. hyiero

    hyiero

    Joined:
    Jun 12, 2015
    Posts:
    7
    Figured this out pretty quick once I took a step back and I thought about what unity was doing behind the scenes. When unity scales down or up it is just taking ratios from the reference resolution to the current resolution and scaling by that factor. But when you add to the gridlayout it uses padding and spacing directly based on current resolution . I needed to override the base spacing and padding with those using the ratio from my reference resolution and current screen resolution