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

how to calculate PPU for image sprites

Discussion in 'Scripting' started by beez-dev, Feb 4, 2022.

  1. beez-dev

    beez-dev

    Joined:
    Aug 13, 2021
    Posts:
    47
    I have an image for creating rounded button in unity, but, If I don't account for the correct PPU (Pixel Per Unit) value, the button gets distorted (I'm even using sliced images):

    upload_2022-2-4_13-47-15.png
    Through trial and error, the PPU value of 300 seems to look like the original image: upload_2022-2-4_13-47-58.png
    but, I don't know a way to confirm if that is correct. How would we actually calculate the PPU value to use for images?
     
    Last edited: Feb 4, 2022
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    I'm a bit rusty with the UI but try checking out Canvas Scaler component. Start tinkering from there and it'll get you somewhere. (Keep in mind that you can set PPU for your Sprites and then there is some sort of synergy going on here.)
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Btw, for such buttons anyway, you should configure 9-slicing with your graphics, this will prevent the stretching as shown. But the PPU settings are simple: PPU = how many pixels per world unit. And you can see the scaling amount in the transform, so this should be fairly easy to calculate.

    That said, setting PPUs have nothing to do with the stretching you're seeing.

    I'm also seeing you have some dead space above the button graphics, so that's also your problem maybe?
    Because by adjusting PPU, you just allow it to breathe, it seems. Something else is off.
     
  4. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    If you set native size it will scale to the image's dimensions. If the dimensions are ever changed unproportionally then you may see distortion.