Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

uGUI with SpritePacker/TightPackerPolicy - it reveals the nearby sprites

Discussion in 'UGUI & TextMesh Pro' started by StarManta, Aug 22, 2014.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    7,851
    I have an issue with using packed sprites in the GUI. While setting it up, they look fine, but once I enter play mode (presumably when it switches over to using the packed sprite image) I start getting these artifacts. It took me a minute to figure out what I was seeing, but I figured out that it was simply using a rectangular "mesh" instead of the sprite-shaped mesh generated by the sprite importer, and thus was picking up all the tightly-packed sprite images near it in the atlas.

    One screenshot shows the UI element in game; the other shows the packed sprite atlas. (the hand-drawn "world" thing and the stylized "R" are the artifacts in question)

    Is this just going to be a fact of life (at least for 4.6.0)? Is there a way to make it use the sprite's shape? For now I removed the packing tags from the affected UI elements, but I'd like to get them into an atlas for efficiency.

    I need tight sprite packing for most of the sprites in my project, and if not for this issue, it would work well for UI sprites as well. The sprite packer doesn't let me choose packing policies on a per-atlas basis, so I would have to write a custom packer policy to make it pack these loosely while the rest are packed tightly.
     

    Attached Files:

  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    As far as I know only rectangles are supported at the moment. Theoretically you could create your own class which supports the tight shapes as well. However, that is not what I wanted to write.
    It doesn't matter which packing policy you are using, you can still change the way the packing happens per atlas using string tags:
    http://docs.unity3d.com/Manual/SpritePacker.html
     
    StarManta likes this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    7,851
    Thanks, works as expected. :) That'll do nicely until the UI supports non-rect sprites.
     
  4. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    62
    You can use the `Use Sprite Mesh` option in the Image component > Image Type to specify you want to render inside a polygon (actually a set of triangles) rather than a rectangle (actually 2 rectangles).

    I tested and this removed the artifacts around my sprites using tight packing.
    I don't know if the surrounding polygon is guaranteed to never touch neighboring sprites in the sprite atlas, though.
     
unityunity