Search Unity

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

Discussion in 'Getting Started' started by AidanofVT, Sep 16, 2020.

  1. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    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?
     
    N8W1nD likes this.
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    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.005>
    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.
     
    Last edited: Aug 19, 2022
    N8W1nD, TwoBearBox and Schneider21 like this.
  3. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    @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?
     
    N8W1nD likes this.
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    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.
     
  5. pantang

    pantang

    Joined:
    Sep 1, 2016
    Posts:
    219
    Thank you just answered today's question, so its best to make the UI a standard size and then use scalling to get it to fit where you want when in world space. Lucky I saw this I had went the other way had set my first batch up at .4 size :p
     
    N8W1nD likes this.