Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why do Sprite image and UI Panel dimensions not match?

Discussion in 'Getting Started' started by nijagu, Mar 4, 2017.

  1. nijagu

    nijagu

    Joined:
    Feb 12, 2017
    Posts:
    8
    In 2D mode, why do the 2D Object (Sprite) image and the UI Panel of the same dimensions not match?

    Thanks in anticipation

    -u
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I guess that depends on what you mean by "match". Have you tried the "Set Native Size" button on the inspector for the Image component?
     
  3. nijagu

    nijagu

    Joined:
    Feb 12, 2017
    Posts:
    8
    Thanks
    I think you are referring to the UI Image component, whereas AFAIK there isn't such a button on the Sprite Renderer component, which is part of the 2D Object (Sprite).
     
  4. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    The issue is that the UI is really 2D and it's native size and resolution is dictated by the device it is running on, whereas the 3D environment does not have any imposed size or scale. Lastly, 3D space does not understand pixels or resolution. 2D sprites are just quads and live in 3D space. While the image on the sprite is 2D and is exactly the same as UI elements, it is actually on a 3D object and must abide by the rules of 3D space. They are vastly different elements and must be treated differently as Unity does.

    You can set the UI scale in the canvas renderer component to represent the same scale as your sprites.
     
  5. nijagu

    nijagu

    Joined:
    Feb 12, 2017
    Posts:
    8
    Thanks,
    I’m not sure I understand everything that you say.
    I am running Unity 5.5.1f1 in 2D mode and Game View is set to 4:3
    The [greyed out] Rect Transform tab for the Canvas has a Width of 800 and Height of 600.3781
    The Scale values (X, Y, & Z) are set to 0.66125
    The Canvas Scaler has a Reference Resolution of X: 800, Y: 600.
    Screen match to Match Width or Height, with Match set to Width.
    To get the Rect Transform Scale to display a value of 1, the Canvas Scaler requires a reference resolution of 529 x 397
    The issue becomes perhaps more apparent when adding a 2D Object (Sprite) directly into the Hierarchy e.g. when adding a 800 x 600 image.
    The 2D Object Transform Scale X and Y values must be set to 1.66125 (or thereabouts) to render the object at its native size.
    Note 529 / 800 = 0.66125
    Regards

    -u
     
  6. nijagu

    nijagu

    Joined:
    Feb 12, 2017
    Posts:
    8
    For the default Aspect Ratio, Standalone (1024 x 768), it is not unreasonable (albeit wrong) to presume each grid cell will be 768 / 10 units, or 76.8. What does the value 1024 x 768, which seems inappropriate, mean? This is the question that I have been asking and in case anyone is interested, the answer assuming a (default) Pixel Per Unit ratio of 100, appears to be 1333.333... x 1000 px. Duh!
     
    nrj likes this.