One of the very long-time needed features for the sprite packer was the ability to sort the sprites to be packed individually, to avoid using multiple big textures when you pack sprites that are used in the same screen together, instead of randomly as it is now.
But not a single word about it other than the changelog. Does anyone know or can guess what’s going on here? Can we utilize this to implement custom sorting?
Totally understand where you’re coming from, dude. It’s been a hot minute since we’ve been needing that sprite packer feature, right? But hey, guess what? It’s finally here - sortin’ those sprites individually and avoidin’ the hassle of those big textures. Super stoked about it! Now, I’m not exactly sure about the details, but I reckon we can definitely use this to implement some custom sorting.
That doesn’t look like a sample. I’ve checked inside and it’s a big script with mostly internal static methods/structs/classes. I don’t think it’s anywhere near an example. Appreciate the effort but doesn’t look like something usable sadly
Obviously it can be dissected and be used in the end to create something of our own but that is way too much effort up to a point where makes using the sprite atlas system meaningless anyways.
Sounds like the problem isn’t in sample but mismatch between what scriptable sprite packer does and what you need. As always there is a tradeoff between customizability and ease of use.
There are multiple aspects to sprite packing:
what sprites are in the same sprite atlas → optimal choice for this will depend on how the game uses those sprites, which ones are more likely to be displayed together
how sprites within atlas are positioned, what order an positioning gives maximum packing → also known as “2d bin packing” this is a very hard computer science problem, with no known optimal solution, only a bunch of heuristics
pixel filling between the sprites for padding reason, and maybe some special needs if you are using some specialized shader or other effect.
If you only need a simple high level control over which sprites are packed together and which ones are separate, then it might be easier to just create create a bunch of sprite atlases, and use the Unity - Scripting API: SpriteAtlasExtensions api for adding specific sprites in specific groups based on whatever your constraints are. This was already possible before scriptable sprite packer.
Scriptable sprite packer gives low level control over the later two aspects which was previously not possible. 800 lines of code for those kind of things, performance optimized with job system and burst, and low level operations like pixel processing and triangle rasterization, a bunch of debug and testing code, isn’t so bad. You could easily end up with more than that just for binary packing part if you tried to implement some of more advanced binary packing algorithms. You could also use it for first thing but it’s slightly too low level API for that purpose, at least not without building a higher level API on top of scriptable sprite packer.