Search Unity

Sprite Atlas Optimization for shared sprites

Discussion in '2D' started by AlanPereiraArt, May 7, 2020.

  1. AlanPereiraArt

    AlanPereiraArt

    Joined:
    Apr 29, 2014
    Posts:
    17
    Hello guys, I have an amount of 5 screens that shares some assets, what is the best solution to optimize that by using sprite atlas?

    Solution 1)
    • Create a Generic sprite atlas;
    • and an individual Atlas for each screen with the individual sprites only.
    Would it be a problem if a screen uses about 20% of the generic atlas?

    Solution 2) Create an individual atlas for each screen containing the generic sprites used and the individual sprites.
    In this case, the generic sprites would be present in more than one sprite atlas. Which gives an warning in Unity saying it uses an default sprite atlas, I suppose it doesn't work as expected and is not the best solution.
    Sprite sprt_bg_star matches more than one built-in atlases. Default to use the first available atlas.


    Solution 3) Create an individual atlas for each screen with duplicated generic sprites.
    This one is a solution similar to the second one, but in this case the generic sprites are duplicated and doesn't not give the warning that will use a default sprite atlas.
    The big problem here is that the size in disk is increased (actually more 20MB for each screen) and it is also bad to manage duplicated assets.

    Me preferred is the simpler solution 1, but I coming here to know if you guys have a better solution for this case.

    Thanks in advance
     
    Thurgh likes this.
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    To minimize size and to improve performance, I would suggest the following :

    1) Use GetSprite API to create only the required Sprites on loading. This solution requires no duplication and should work straight-away with any Atlas (Master/Variant). It does require loading/managing Sprite assets from Atlases on the runtime.
    https://docs.unity3d.com/ScriptReference/U2D.SpriteAtlas.GetSprite.html

    2) Use Late-binding. This is very flexible and extendable to support AssetBundles etc..
    https://docs.unity3d.com/ScriptReference/U2D.SpriteAtlasManager-atlasRequested.html

    I would also suggest that you have 1 or N SpriteAtlas for common sprites and have 1 Atlas for sprites that are unique to each screen.
     
  3. odaimoko

    odaimoko

    Joined:
    Jun 28, 2020
    Posts:
    9
    Hi OP, have you found your way of managing these sprites? I recently encountered the same problem and glad to learn from others!