Search Unity

Question Migrating Sprite Packer Legacy to Sprite Atlas in asset Bundles

Discussion in 'Asset Bundles' started by TobyKaos, Jun 29, 2021.

  1. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hello, I am facing a headache.

    I used sprite packer legacy by using tag. This create Atlas and I assigned assetbundles to my Sprites.

    Then I downlad assetBundles and the sprite appear.

    Now I want to use the new Sprite Atlas. Then I create spriteatlas file with my Sprite in it. I assign Sprite and spriteatlas to assetbundles.

    But when I download assetbundles and load it the sprite no longer appear (all is white).

    I am missing something. Tell me not we must call LoadAsset<SpriteAtlas> ? This is weird if we must do it.
     
  2. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    I read the doc and find this:
    "If you want to pack the Sprite Atlas into an AssetBundle and Include in Build is checked, then you are using Late-binding and it will automatically load the Atlas."

    Then it is what I am doing. I create assetBundles, I mark my spriteAtlas as assetBundles and the sprites too (I do not think it is necessary but I do)
    I let the checkbox "include in build" checked. Then when I launch the game I load the assetBundles and the sprites are white as if sprites are not automatically loaded.

    The expected behaviour is that spriteAtlas are automatically loaded. Right?
     
  3. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    I try to add atlasRequest callback but it is never called. Then I cannot load SpriteAtlas.
     
  4. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hooo. Seems to works with my SpriteRenderer but not with UI Image. Right?
     
  5. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Then:

    1/ I create assetBundles with sprites and sprites atlas inside (not sure I must include Sprites)
    2/ I check include in build
    3/ No scenes refers to sprites because scenes are in another assetBundles
    4/ I start the game, download AssetBundles and load assetBundles and load the main scene
    5/ My UI is white
    6/ In level game, sprite renderer is ok

    If I unchecked include in build then atlasRequest is called and I can do the late binding. But I prefer check include in build it is more easy :)

    Conclusion: Sprite Atlas in downloadable AssetBundles does not work for canvas UI.

    Edit: I build and test on real device and my UI sprites appears.
    Conclusion: Unity Editor is buggy with sprite atlas and asset bundles for the canvas UI.
     
    Last edited: Jun 30, 2021
  6. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    I have 2 assetBundles, one for the scenes and one for the sprites.

    If I do not include Sprites and Sprite Atlas in the assetBundles "sprites" then my Sprites are included into my assetBundles scenes.

    It is not an expected behaviour because spriteAtlas create Atlas texture that is packed into assetBunbles alongside spriteAtlas. If I include my Sprites too then the size increase. If not then the scenes assetBundles size increase a lot and worth the spriteAtlas will not been used.
     
  7. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hum, I think the assetBundles browser tool only show Sprites references in asset Bundles. For instance a Sprite of 1Mb ETC2 8 Bits take only 39.9Kb in assetBundles.
    It is the size in the spriteAtlas I think.

    But in the browser tool we do not see the spriteAtlas generated textures.