Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Sprite Atlas and Sprites in Resources folder

Discussion in '2D' started by Democide, Dec 11, 2018.

  1. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    295
    So, I've just created an atlas A and put a number of Sprites into it. Both the atlas and the sprites are located in resources/. Then i have an atlas B and put a set of other Sprites into it. Here both the atlas and the sprites are NOT in resources/.

    Now when I check out the Last Build Report I can see the size of the various files in the build:

    Now for atlas B, the size of the build-assets are as expected for the size of the textures used. And the build-assets of the sprites used for atlas B only have small filesizes (usually sub 1kb) which indicates that there's only meta information pointing to the Atlas is included, but no actual texture information. Which feels correct since all the texture information is in the atlas B build-asset.

    However when I look at atlas A things are different: The atlas build-assets have the expected size. However when I look at the build-assets of the sprites used for Atlas A things are different. Here the filesizes of the build-assets are as big as the original sprites, which indicates that the entire texture information is included. This makes me wonder if the atlas is even used in that context.



    Does anyone have any insight?

    Edit: Did some further experiments.

    1. Does it use the Resources/ SpriteAtlas?
    Test setup: New project. Added a single large sprite, made it create a mip-map (blur) and put it on a small ui image. Then I created an atlas for that single sprite, and disabled mipmapping there. Then I put both atlas and sprite in the resources/ folder and created a test build.

    Results: Image was crisp - i.e. used the SpriteAtlas. So that's good.

    Update: Tried loading the sprite not by dragging it into the slot but by loading it via Resources.Load. Same results - SpriteAtlas was used.

    2. Does the build contain the Resources/ Sprite tex information?
    Test Setup: As above. Built once with the sprite in the resources/ folder, once with it outside, and once without an atlas.

    Results:
    Build with atlas + sprite outside resources folder: base size
    Build with atlas + sprite in resources folder: base size + sprite size
    Build without atlas: base size - atlas size.

    Less good, that means Unity actually adds the sprite's texture information to the build.
     
    Last edited: Dec 11, 2018
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    220
  3. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    295
    Which is understandable, but strange when they are also present in the atlas.
     
  4. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    71
    Was just Googling to find out the answer on this, and make sure it works the way we expected (which is indeed the way it works / is by design).

    By putting the 'sprites' (textures in reality) into the Resources folder, that allows you to Resource.Load() / reference the actual Texture2D. That obviously requires they be present, so it means they have to be packed in the build. If it automatically packed them into the atlas and did NOT keep the Textures in the build, then there would be no way to reference the texture itself -- so if you wanted to use both SpriteAtlas along with maintaining the ability to reference the texture, you'd have to duplicate the assets inside of & outside of the Resources folder.

    I actually thought we were going to have to do that duplication (which would be really ugly but is precisely what my initial test case did), but I'm glad to find out -- via this thread -- that we won't have to, which is great and makes complete sense too. Am glad this is by design, and completely agree with the design decision.

    FWIW, this gives you best of both worlds; if you only want the Sprites accessible (but not the original textures) simply put your SpriteAtlas-referenced sprites/textures outside of the Resources dir. If you do want access to the actual/original Texture, put it inside. That you have both options/tools for different scenarios is great. :)

    Now if only we could get TMPro to use SpriteAtlas instead of a 'custom asset', hah! ;)