Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. 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

Sprite Atlas and Sprites in Resources folder

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

  1. Democide


    Jan 29, 2013
    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.

    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


    Unity Technologies

    Apr 7, 2015
  3. Democide


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


    Mar 14, 2016
    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! ;)
  5. markv12


    Dec 31, 2013
    This thread has answered most of my questions, but a problem remains.
    I understand why the original textures are included in a build if they are actually inside the resources folder, but it seems like the original textures also get included in the build if anything in the resources folder references them.

    In my game I have a player prefab that is in the resources folder. I need to be able to instantiate the player in code as I don't want to have to put the player prefab in all of my scenes.
    The player has many animations which reference sprites that are not in the resources folder. I want to be able to pack all the player sprites into a sprite atlas and not include the original images to reduce the build size.

    Is there a way to support instantiating the player prefab through code that does not result in the original image files being included in the build? I don't need to be able to load the individual images through code.

    Any suggestions are greatly appreciated!