Search Unity

Sprite Mesh Type: Full Rect vs Tight (Mobile Performance)

Discussion in 'Getting Started' started by Sparticus, Jun 15, 2022.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hey all,

    I am making a mobile game where obviously performance is always a concern. I see when you import an image and set it to a Sprite, you get the option to choose it's Mesh Type. Full Rect or Tight.

    Full Rect : Rectangle mesh equal to the user specified sprite size.
    Tight : Tight mesh based on pixel alpha values. As many excess pixels are cropped as possible.

    In other worse, Full Rect is 1 big quad (rectangle) that wraps the entire image. It will include any transparency around the edges. Tight will use many triangles to almost go around the edges of your image to limit the amount of whitespace/transparency included.

    I have read that Full Rect will have a lot less triangles whereas Tight will have much more. The advantage to Tight is there will be a lot less overdraw and alpha blending (it doesn't need to draw/calculate empty alpha pixels.

    Some sites I read claim for mobile to just use Tight as Alpha Blending and Overdraw is expensive. I am not sure changing every single sprite in my game to Tight is the best option. What about images that are square in size and have little to no transparency around the edges? Seems to make sense those I'd leave at Full Rect.

    Anyone know?

    Thanks!
     
  2. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Well, unless I am missing something, I need to make everything a Full Rect. Since I use Unity's Sprite Sheets, the Tight mesh type seems to grab parts of adjacent sprites (you can see parts of the other sprites around the edges).

    If anyone has any solutions or experience in this area it would be appreciated!
     
  3. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    204
    In general, overdraw is bad for performance on low-end devices and some mobile devices will fall into that category.

    By default when you import your Sprites into Unity, they should have their Mesh type set to "tight" so you shouldn't have to change anything.

    In that case you would probably be better off with a quad. If you want to do some micro-optimisation you could even draw an outline yourself in the Custom Outline section of the Sprite Editor.

    Can you share how your Sprites are laid out in the Sprite sheet?
     
  4. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Ya sure. So if I change some of my game icons to use a "tight" mesh type, this is how it shows up in my game :

    upload_2022-6-21_15-5-3.png

    Those red bits under my arrow icon should not be there. They are part of a different image in the sprite sheet (I assume)

    I am trying to find out how to see the Sprite Atlas Unity creates for me, but the "Pack Preview" button doesn't seem to do anything (It used to show a zoomed in view of the sprite sheet, doesn't anymore, not sure why)

    upload_2022-6-21_15-12-45.png
     
  5. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hmm, I just saw this post.

    upload_2022-6-21_15-15-54.png

    I disabled "tight packing" in the Atlas Unity creates and the issue goes away.
     
    MarekUnity likes this.
  6. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    165
    In order to use Tight Packed sprites in the UI you should enable Use Sprite Mesh in the image component:
    upload_2022-6-22_12-12-9.png


    It's still there but maybe hidden at the bottom. Click that double line with Left mouse button to expand it or with Right mouse button to zoom it:
    upload_2022-6-22_12-17-52.png
     
    Yuchen_Chang and Discipol like this.
  7. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Thanks man, you were right :)