Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

I really don't understand how UI scale works in world space.

Discussion in 'Getting Started' started by AidanofVT, Sep 16, 2020 at 2:09 AM.

  1. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    38
    I'm trying to create a UI overlay for an entity in my game. Things in my test scene are on the scale of 1-10 Unity units.

    I create a world-space canvas under the game object; it's 100 by 100. No problem, I just resize it. I create a button subordinate to the canvas. It's 160 by 30. Resize to 5 x 5. Now it's super pixelated, as though the button is intended to be viewed from a much wider scale. After some fiddling, I fix that problem by reducing "Reference Pixels Per Unit" on the Canvas Scaler component. Not sure how that works, but it works. I try to change the text on the button. No text shows. On a hunch, I restore the button to it's original size, and the text is there. When I shrink the button, the text stays the same size and the button contains only white-space. This is 14pt font, which means that it should be 14 pixels high. But on what monitor?

    These 14pt letters would seem to be about ten unity units high. I can't set the text to 0.3pt size; that's ridiculous and Unity won't let me. Obviously, I'm failing to understand something very fundamental about scale in Unity. Would someone help me, please?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,946
    To make a world space canvas act the way you expect, you'll want settings similar to these:

    Transform scale: <0.005, 0.005, 0.05>
    Transform width: 400 height: 300
    Canvas render mode: World Space
    Canvas Scaler, Dynamic Pixels Per Unit: 1
    Canvas Scaler, Reference Pixels Per Unit: 100

    The key is probably the first one above. If you don't scale your canvas down quite a lot, you will have suffering and grief.
     
    Schneider21 likes this.
  3. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    38
    @JoeStrout

    Looks like that does it. Thank you! But now I wonder: since this feels like a fairly extreme squeezing of the Unity standards, might it be better in the long term if I just scale everything up by a couple orders of magnitude?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,946
    No. The standard is for 1 unit of Unity space to be 1 meter of virtual space, and there's no reason to deviate from that. Canvases are designed with a different convention, 1 unit ~= 1 pixel, but that was because they were originally intended for screen-space work. When you're using them in world space, it is expected and perfectly normal to scale them down.
     
    ippdev likes this.
unityunity