Search Unity

Sprite Packer

Discussion in 'Assets and Asset Store' started by Darkcoder, Dec 14, 2013.

  1. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    NOTE: This asset has been deprecated from the Asset Store because Unity now comes with its own built-in Sprite Packer tool that largely does the same thing, and the sales from this asset aren't strong enough to justify my time to update it.

    If you've purchased Sprite Packer then you can still download it, but it will no longer receive any updates. I understand this will disappoint some users, so to make up for this:

    All customers are automatically eligible to get a free copy of my new Lean Texture+ asset, which allows you to do texture channel packing, generate normal maps, and many more really useful texture modifications. You can find the new asset HERE, where you should be able to download/install it in any project running at least Unity 2019.4.12.

    Sorry for any inconvenience!



    What is it?

    Sprite Packer is an easy to use tool that can efficiently pack your textures and sprites into a single sprite atlas.


    Why would I need this?

    If you're using Unity's new 2D features then you might have noticed your draw call count going through the roof.

    If you're making a mobile game, then keeping your draw call count down is vital, and this tool makes it incredibly easy to do so.


    Why should I use this instead of the alternatives?

    • Sprite Packer is the easiest to use by far. Everything about it was designed to make sense, while giving you full control.
    • Sprite Packer automatically rebuilds texture atlases when it detects changes. This speeds up workflow a lot.
    • Sprite Packer works with any texture or sprite, so you don't have to fiddle about with the texture import settings.
    • Sprite Packer trims the edges of all your textures to save space (can be disabled too).
    • Sprite Packer is designed to work with terrain tile sheets, so you don't have to worry about ugly seams at the edges.
    What's the workflow like?

    Step 1: Create a Sprite Packer

    Step 2: Add Some Textures

    Step 3: Tweak Packing Settings

    Step 4: Make Your scene

    Enjoy 1 Draw Call

    You can also watch a video of it in action.


    Where can I get it?

    You can get it from the Asset Store.




    Thanks for reading. If you have any questions, feel free to ask!
     
    Last edited: Jul 30, 2021
    Shodan0101 and Gozdek like this.
  2. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Hi,

    How do you manage the pivot points?
    How do you exactly manage the removing of sprites inside your Atlas? I see in your video that you keep the reference of the sprite, what if I remove 1à sprites? You keep every reference? Is it related to the IDs Unity is using concerning sprites?
     
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The latest version has two pivot point modes:

    - The first is to centre the pivot point after the image is trimmed. This is useful for just generic sprites with lots of random whitespace around them.
    - The second is to retain the pre-trimmed pivot point. By default this pivot point will be the centre of the image (i.e. if you send Sprite Packer a normal Texture), but if you pass a Sprite or a Multi Sprite then you can specify your own pivot points using Unity's Sprite Editor, and as long as you don't hit trim within that editor, it will work very well for animated sprites that have a lot of whitespace around them, but need to act as if the whitespace is still there.

    I don't know if I explained that well, but I will be making an updated tutorial video to showcase this new feature.


    To remove a sprite from the atlas you can either delete the source texture and rebuild the atlas, or set the texture entry to null and repack it. Doing this will completely remove the sprite from the atlas texture, but the actual sprite entry will remain. This is because sprites inside a multi sprite are referenced using a Sprite reference and integer index, so I can't actually remove the sprites from the sprite array without potentially corrupting some scenes.
     
  4. FamerJoe

    FamerJoe

    Joined:
    Dec 21, 2013
    Posts:
    193
    This is not true from my experiences. I have a few sprites I need Pivot Left, and without trimming, and specifying Left pivot, they still seem to be center pivot on the sprite sheet. Am I doing something wrong?

    Other than that, this is a great time saving asset.
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Interesting, I just did some testing and it seems that custom pivot points don't work correctly if your source sprite has the Sprite Mode set to Single. This appears to be a bug with Unity, because the texture importer's spritePivot value always returns 0.5, 0.5, regardless of what you set.

    However, you can work around this issue by setting the Sprite Mode value to Multiple, and just set up one sprite.

    I will release an update that warns you if you try to pack a sprite that uses the Single mode in combination with Keep Pivot. Thanks for pointing it out.
     
  6. FamerJoe

    FamerJoe

    Joined:
    Dec 21, 2013
    Posts:
    193
    Great! Thanks.. I'm surprised this asset hasn't gotten any reviews - i'll write one later today.
     
  7. FamerJoe

    FamerJoe

    Joined:
    Dec 21, 2013
    Posts:
    193
    In the 1.0.6 release, one of the change log notes was "Remove Missing Sprites" option added to SpritePacker context menu, however I can't seem to find that option while highlighting the SpritePacker prefab and right clicking. Is the option somewhere else?
     
  8. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yeah, you either need to click the gear icon in the SP_SpritePacker inspector, or right click the component name:

     
  9. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Hi, would your tool allow us to import a texture that's a little image in a big empty box, and keep the entire empty box as a tile rather than trimming out all the unused space? Our images are all created within the same canvas area, and we are layering those images on top of each other, so need to keep the exact placement within the box.
     
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, this feature was introduced in Version 1.0.5, and the 'Trimmed Animation' demo scene shows it in use.

    If you choose to buy it and have any issues then please post here :)
     
  11. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Great tool, very useful! Exactly what I had expected Unity to put in with their Atlas support, but was missing. I do have a request for the next version: the ability to either set default values for the Trim/Keep Pivot checks, or a way to mass set those values. In our game we need to turn off Trimming for almost everything we put in there, and it's a pain to do it one by one, and hope we didn't miss one.
     
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Good idea, I just added this feature. I also found a solution to the Keep Pivot value not working with Single sprites. However, it seems assets are currently taking ages to review, so if anyone wants an advance copy then send me a PM!

    [Edit] Seems like it was quick this time. Version 1.0.9 is now live!
     
    Last edited: May 3, 2014
  13. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Hi, I just grabbed the latest version of SpritePacker, and if I use that version to Rebuild an old SpritePacker prefab, I end up with a whole bunch of "Missing" things in the resulting Atlas. All the sprites seem to be present in the Atlas (after all the "Missings"), but prefabs referencing the sprites that used to be in the Missing section lost their references.
     
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    In version 1.0.6 I fixed a bug where Unity would throw errors under certain circumstances (due to a Unity bug). Unfortunately, fixing this bug meant that all texture and sprite references would be lost, forcing you to essentially redo your atlases.

    I added a warning to the Version 1.0.6 release notes about this, but perhaps I should have carried the warning over to more versions. If you don't need the new features added in 1.0.6/1.0.7/1.0.8 then I can send you a copy of 1.0.5, which should still be compatible with your current atlases.
     
  15. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Hmm, we actually started with version 1.0.7 before upgrading to 1.0.9. But we've only used it for a couple atlases so far, so I can recreate them.
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Strange. The texture and sprite references are just GUIDs, so maybe something caused those to change? I could make it harder to break in future versions by also storing a path as a fallback.
     
  17. Tekksin

    Tekksin

    Joined:
    Oct 20, 2013
    Posts:
    32
    -Does this work with the free version of unity? I realize you have to buy this, but does it work fully with the free version of unity?

    -Can the sprites that are packed together be used for animation? I already have all my animations and prefabs set up using separate sprites. Will I have to recreate these in the animation/animator window, and then update the prefab?

    -Will I have to recreate the prefabs for all of my objects using the new sprites in the sprite packer? If the sprites are potentially all gathered from the sprite packer, will I be able to then delete the old singled out sprites?

    - Do the sprites put in to the sprite packer all have to be the same size? I use relatively small objects, but things like fences are wider than things like bushes. Some clarification here would be nice.

    Let me know! I've been searching on the internet and cannot find definitive answers.
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, it fully works with the free version of Unity.


    Yes it can be used for animation (it includes an example scene of this), but you will have to set your sprite references up again. This is because it doesn't modify your existing sprites, it instead creates a new set inside an atlas.


    You don't have to delete your old sprites, but you will have to update the Sprite references inside your SpriteRenderer components.


    No, the sprites you put in the packer can be any size you like.


    ----------------

    If updating up the sprite references is an issue, then perhaps I could make a tool that finds all references to the unpacked sprite, and replaces them with the packed version. But I'll have to investigate this quite a bit, as the last thing I want to do is damage any prefabs or scenes!

    [Edit] I just finished writing this tool and submitted it to the Asset Store. It will come with Version 1.1.0 :)
     
    Last edited: May 14, 2014
  19. Shiny

    Shiny

    Joined:
    Feb 13, 2013
    Posts:
    2
    Hi, i was thinking to buy Sprite Packer but i have a doubt about it:

    Can i put my atlases in the resource folder and load the content inside them directly with script?
    I'm asking this because, as far as i know, the built in packer for unity pro dosen't give you this possibility and i have no clue if this tool can do it.
     
  20. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, in c# you can use: var myAtlasSprites = Resources.LoadAll<Sprite>("YourAtlasPath");
     
  21. Shiny

    Shiny

    Joined:
    Feb 13, 2013
    Posts:
    2
    Thank you very much for the info :)
     
  22. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Hi! Could you please implement keeping not only the pivot but also the borders of the sprite?
    I just burned myself on this issue, I cant pack nine-sliced elements.
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Thanks for pointing this out, I hadn't considered it.

    This bug is now fixed and will be included in version 1.1.1. I'll send you an advance copy of it now.
     
    MaxEden likes this.
  24. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Everything is perfect now! Great asset!
     
  25. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    There is a problem with Atlas that are in Advanced texture type
    If you add them on the SpritePacker Atlas, they are coming in one piece.
    This is not a big deal but would be good to have either an error message or the possibility to import this kind of texture too :)
     
  26. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Thanks for finding this bug! It's now been fixed and is pending review by Unity, I'll send you an early copy now.
     
  27. YogieAditya

    YogieAditya

    Joined:
    May 27, 2013
    Posts:
    2
    Hi, i just purchased your product, but i have problem here..

    I tried to build the sprite packer and its worked, it produces 1 draw call..

    The problem is, i tried to compare the single sprite image and the sprite packed with your packer, when i try to zoom in the same scale, the sprite from your packer is so so blurry, tried with max rects and Guillotine Algorithm, max rect produces more more blurry sprites.. Any idea how to fix that?..

    My single sprite has around 500px-1000px width and height, and the packer size is 4096x2048..

    Thank you.. :)
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Did you try changing the atlas texture format to automatic truecolor? By default it's compressed, which has a lower quality.
     
  29. YogieAditya

    YogieAditya

    Joined:
    May 27, 2013
    Posts:
    2
    Allright cool! it fixed now.. :) Thank you, and thanks for your awesome packer..
     
  30. m3ndi3

    m3ndi3

    Joined:
    Mar 6, 2012
    Posts:
    18
    Hi I just started using your sprite packer and it is amazing! One thing though, some sprites are having different scaling when they get sprite packed.... This is a big deal for me because I have a bunch of sprites with hit boxes, and when I use the sprite packed sprites, the sprite's are scaled smaller than the original sprite. The actual size remains the same so it's very confusing :< Please help!

    p.s. this only happens to some of my sprites.. As you can see in the screenshot, the two blue flowers have different sizes but the actual game objects are the same size, same scaling etc.
     

    Attached Files:

    Last edited: Oct 15, 2014
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Interesting. Is the source texture (i.e. the original blue flower) using the Sprite Texture Type, or using the Truecolor texture Format? If so then I can't really think of a reason why this would happen to only some sprites in your atlas. If it's not too much hassle, could you try making a new atlas with as few sprites as possible until this issue occurs, and send me a Unity package, or project file demonstrating this issue?
     
  32. Caio_Lib

    Caio_Lib

    Joined:
    Mar 4, 2014
    Posts:
    83
    m3ndi3, I was having the same problem, in my case Max Size value was wrong.
    I had to increase to Sprite Packer's Max Size and change Sprite's Max Value too. ( The value was less than the Sprite's size )
    Hope that solves for you.
     
  33. ez06

    ez06

    Joined:
    Feb 18, 2014
    Posts:
    45
    Hi Darkcoder,
    I have a problem with the image quality in my Sprite Packer object.
    The original sprites are of good quality. They sliced with Unity's Sprite Editor (Filter mode: Bilinear, pixel to units: 100)

    But when I add them to the Sprite Packer object, they become very blurry.

    Also, the fact that it's blurry causes the individual sprites to slightly overlap the neighbouring sprite and this is visible in the scene.

    What can I do to maintain the same quality as in the original sprite?
    Is there a way I can set a "safety distance" between each sprite to ensure they don't overlap each other?

    Thanks in advance
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Check the 'Format' of the generated atlas texture, is it set to Automatic Truecolor?

    Also make sure the Max Size setting is set to at least the size of your atlas texture. By default this should be set to 4096.

    If you want to adjust the padding around a specific image then select your sprite packer and click on one of the texture grey boxes to reveal the advanced settings, from there you can adjust the 'Border Size'
     
  35. ez06

    ez06

    Joined:
    Feb 18, 2014
    Posts:
    45
    Thanks for that, I've been working on improving graphics performance.
    But I'm encountering problems with the Transparent Rendering; I have too much of it in my Profiler.

    To reduce Transparent Rendering, I'm trying to use "Mesh type = Tight" in Advanced settings of Texture Importer but it doesn't seem to take effect in Sprite Packer.

    Does Sprite Packer supports the Tight Mesh of Unity Pro?

    Thanks a lot
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The 'Tight Mesh' packing just means sprite rectangles can overlap as long as the underlying sprite polygons/meshes don't overlap. Sprite Packer just uses rectangle packing because Unity doesn't provide an API to read/write this polygon/mesh data.

    However, all Unity sprites (including Sprite Packer atlases) have a polygon/mesh automatically generated for them, so you will get the benefit of reduced fillrate (i.e. less transparent rendering). You can confirm this by changing the material on your Sprite Renderer to None/null and see the shape of the magenta sprite border.
     
  37. ez06

    ez06

    Joined:
    Feb 18, 2014
    Posts:
    45
    Thanks for your response.
    But when I set the material to None, the sprite simply disappears. There is no magenta sprite border. Does that mean that the mesh was not generated?
    I get 95% transparent rendering & 5% opaque rendering, so there must be something wrong in what I'm doing.
     
    Last edited: Dec 2, 2014
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The default sprite material is dual sided, but the none/null material isn't, so try checking the back side of your sprite in the 3d scene view.

    I'm guessing in your project you have many full sized sprites covering the screen (i.e. a lot of transparent fillrate usage). This will always be a massive bottleneck in rendering of any scene, and the only ways to improve it are to lower the screen resolution, lower the amount of sprites, or lower the size of some sprites.
     
  39. scheck

    scheck

    Joined:
    Dec 19, 2014
    Posts:
    1
    Hi there,
    Was just wondering if I can include a font atlas (and its txt file) inside of a Sprite Packer prefab?
    I'm currently using NGUI's Font Maker, but would like to put everything inside Sprite Packer.
    Thanks for your help!
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This probably wouldn't work, because the font data (txt file) will use static coordinates that will be wrong after the texture gets packed. Maybe if there is some option in the font data to set an offset then it could work with minimal code change.

    I assume NGUI comes with its own atlas system right? If so, you should probably stick to that and use Sprite Packer for your game sprites, that way you get more control over the texture resolution (e.g. for graphics settings), and can play with the texture format, both of which you typically don't want to modify for a GUI.
     
  41. littlefence

    littlefence

    Joined:
    May 18, 2014
    Posts:
    9
    Hey, I'm having some issues with the Clamp feature, hope you can help or offer some advice.

    I have a character that is made up of a number of different sprites, the head, arms etc are all separate to allow for complex animations. When I put the sprites into my scene from the Sprite Packer (set to Clamp), only the most extreme edges are sharp and solid, any other edges that fall between them are blurred.

    Is there a way I can set the sprites up to be sharp along all edges? Point filtering does work, but looks terrible when in motion.

    Cheers
     
    Last edited: Jan 25, 2015
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Can you post a screenshot of what it looks like? The clamp mode just stretches the pixels at the absolute top/bottom/left/right into the padded area around the packed sprite. This is mainly useful for sprites that need to be stretched to fill a large area, for example a fullscreen blood/dirt image that overlays the screen. For character parts you should probably just use the Transparent border mode.
     
  43. Ravanok7

    Ravanok7

    Joined:
    Jul 7, 2013
    Posts:
    8
    Hello Not sure what I'm doing wrong, I packaged everything right, when i try to link i get an error. Appreciate your help.
    NullReferenceException: Object reference not set to an instance of an object
    SpLink_Wizard.LinkInObject (UnityEngine.Object o) (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:241)
    SpLink_Wizard.LinkInComponent (UnityEngine.Component c) (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:233)
    SpLink_Wizard.LinkInTransform (UnityEngine.Transform t) (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:192)
    SpLink_Wizard.LinkInPrefabs () (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:162)
    SpLink_Wizard.DrawButtons () (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:123)
    SpLink_Wizard.OnGUI () (at Assets/SpritePacker/Editor/SpLink_Wizard.cs:90)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:244)
    UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:237)
    UnityEditor.HostView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:129)
     
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I sent you an updated script which should eliminate this error, though I'm not really sure why it would break there.
     
  45. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    Hi there this solution seems interesting and better for us than an external tool like texture packer.
    My question is, sprite packer just generates an atlas correct, like other programs of the sort, no strings attached no overheads or anything. I have to ask, it just seems to good to be true. :D
     
  46. miniPIMP87

    miniPIMP87

    Joined:
    Jul 29, 2014
    Posts:
    1
    Hey, it works fine with the new Unity 4.6 UI ?
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Sorry for the late replies, I didn't notice the messages!

    Yes, if you create a Sprite texture in Unity you can see the 'Multiple' setting allows you to create multiple sprites from a single texture by placing boxes around the texture. Sprite Packer basically packs all your individual textures and sprites into one big texture and sets up these sprite boxes for you, which saves tons of time.


    Yes!
     
  48. SmartyP

    SmartyP

    Joined:
    Nov 15, 2012
    Posts:
    7
    I noticed that the settings for Algorigthm, Max Size, etc. are not showing up in the inspector as shown in the screenshot in this thread and the demo Youtube video - were those removed?
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Thanks for pointing it out. Yes, these settings were removed in version 2, because I didn't think they were particularly useful. I'll update the links and YouTube video.
     
  50. rafaellop

    rafaellop

    Joined:
    Feb 4, 2015
    Posts:
    26
    Hi, do you plan to release a version compatible with Unity 5 ?