Search Unity

Sprite atlas for asset bundle being loaded with main build + images not displaying?

Discussion in 'Asset Bundles' started by roseportalgames, Jun 25, 2019.

  1. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    169
    Hi guys, I decided to start a new thread because the subject moved from image compression to sprite atlas.
    Here's my setup.
    1. I created an Asset Bundle from a scene. https://i.imgur.com/6QFFheF.png
    2. The scene contains a bunch of images. https://i.imgur.com/OhdlrsA.png
    3. I created a Sprite Atlas for the images and checked "Don't include in build". https://i.imgur.com/eN2ykXk.png
    4. I cannot drag the Sprite Atlas into the Asset Bundle, because it seems you cannot manually add files to an Asset Bundle that is created automatically from a Scene. If I try that, I get those red error messages. https://i.imgur.com/tXqnLqX.png
    Now I have two issues:
    1. The entire Sprite Atlas is loaded into memory when I start my game, even without loading the Asset Bundle. There are no pictures in the Sprite Atlas used by the game's main scene. https://i.imgur.com/YNy3W8W.png
    2. When I load the Asset Bundle, the images from the Sprite Atlas are not displayed (however it looks like they are 'found' in the inspector, they are not Missing). https://i.imgur.com/UeOgmWk.png
     
  2. BBB_brunoma

    BBB_brunoma

    Joined:
    Jan 10, 2017
    Posts:
    20
    The Asset Bundle Browser says that those resources are auto included with the bundle but they are not...
    If you have a scene in a bundle only scenes can go in it. If you make another bundle and include those resources that the scene depend on you should be OK. Also, make sure there are no direct references to the bundled scene in the build settings or any direct references to the atlas in any scenes included with the build.

    Edit: The first part of this statement is wrong...
    Everything that is auto included is included. The problem is that it won't include the texture of the atlas if "include in build" flag is off. That is why you were seeing white.
    I guess if you are only using those assets from those scenes it's fine, but if they are used anywhere else, you'd probably want to have them in a dependent bundle to prevent asset duplication. Sorry for the misinformation!
     
    Last edited: Jun 25, 2019
  3. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    169
    Hi, thank you for the reply.

    So I will do this:

    - Make a second asset bundle, only containing the sprite atlas
    - Download and load this second asset bundle BEFORE loading the asset bundle containing the scene

    Is that correct?

    Will the asset bundle containing the scene decrease in file size? Because all those pictures are automatically included based on dependency as you can see.
     
  4. BBB_brunoma

    BBB_brunoma

    Joined:
    Jan 10, 2017
    Posts:
    20
    If you explicitly set the bundle on the atlas, it won't get auto-included in the other (scene) bundle.
     
  5. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    169
    Hmm, but I'm getting the message that it IS included in multiple bundles?

    https://imgur.com/a/YxuxQb5
     
  6. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    169
    BTW, do I have to do anything after downloading the asset bundle that contains the sprite atlas? I'm sure I'm supposed to unload it or something but I've never done that before because asset bundles that contain scenes just work automatically. You can just run those scenes by name after downloading the asset bundle.
     
  7. BBB_brunoma

    BBB_brunoma

    Joined:
    Jan 10, 2017
    Posts:
    20
    It's a bit deceiving in the asset bundle browser but you can get a better idea of what's happening from looking at the log file after making the bundle.

    Notice that the sprite that gets included as duplicate in the scene bundle is pretty tiny - it's the "sprite" part but not the "texture" part. If you don't want that at all you can explicitly add all your sprites to the dependent bundle as well.
    In the dependent bundle the sprite will show up but again it will be tiny as its texture is in the atlas.

    Yeah, you have to make sure all of a bundle's dependent bundles are loaded before getting anything from inside the bundle.

    I think you are OK to unload them when you are done loading whatever you needed from the bundle but I remember there being some caveat that I don't recall.
     
  8. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    169
    OK, thanks! Seems I got it working now for one of my scenes?

    But for another Sprite Atlas, when I click Pack Preview, 80% of the images inside it are missing. Also the asset bundle with that sprite atlas is 24 MB but it should be much smaller based on the images and compression.

    For example there's a texture in there, uncompressed the texture is 8 MB. But I set the texture's own compression to 512x512 pixels so the size is only 50 KB.
    But
    1. it's not showing up in the sprite atlas
    2. it increases the asset bundle by 8 MB

    What?!

    Edit: OK after building the asset bundle, the size is only 150KB. Unity what are you doing??? LOL

    I should examine the manifest/log like you recommend.

    But one final question, how come if I click Pack Preview most of the images in the sprite atlas are missing? Weird.
     
  9. BBB_brunoma

    BBB_brunoma

    Joined:
    Jan 10, 2017
    Posts:
    20
    maybe they are too big to fit on one page?
    upload_2019-6-25_17-42-47.png
     
unityunity