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

Dealing with Unity's sprite packer and non-simple images with trimming

Discussion in 'UGUI & TextMesh Pro' started by _glook, Feb 24, 2016.

  1. _glook

    _glook

    Joined:
    Aug 7, 2015
    Posts:
    1
    We're using Unity 5.3.1f1 and trying to use the built in Sprite Packer. We give our UI sprites, such as button sprites, packing tags and they're all put into an atlas.

    When we use Image components in our UI and the "Image Type" is set to "Simple", it works fine. However, when set to "Sliced", "Tiled", or "Filled", while it looks fine when editing the game, when playing the game, parts of other sprites show up at the edges of the sprite.

    My guess is that the DefaultPackerPolicy trims sprites to get rid of transparent parts at the edges of the sprite in order to fit more sprites in one atlas. This is fine with Simple images that use what I assume to be the mask properly to display which doesn't display any parts of the neighboring sprites in the atlas, but this doesn't work so well with UI elements such as buttons which need to be sliced where the mask does not seem to be used at all and parts of the neighboring sprites are shown.

    To really reproduce this, the easiest way is probably to create a couple of sliced boxes (ie buttons) with 50 transparent pixels on each side or something big like that. Give them both the same packing tag and display one of them in your scene with an Image component set to "sliced" for the Image Type. Part of the other box should appear next to the displayed box.

    Anybody know how to resolve this issue? My initial thought was to just disable trimming somehow for either the entire atlas or just specific sprites (like how the "[TIGHT]" prefix works for the DefaultPackerPolicy), but haven't figured out how to do that. I've even tried creating my own packer policy, but I can't figure out how to disable the trimming from here.

    The other option that I've considered is going through and manually trimming each sprite we're using, but our UI is currently using these sprites with the current dimensions in mind, and we'd have to resize a bunch of Images so they look and work the same, which would have to be done manually and is pretty time consuming.

    This would likely also affect the filled images we are using, though I haven't looked into that yet.

    Thanks in advance!
     
  2. enchiridion

    enchiridion

    Joined:
    Oct 29, 2014
    Posts:
    57