Search Unity

Sprites stored via referencing in ScriptableObject not getting loaded when using AssetBundles

Discussion in 'Asset Bundles' started by xVergilx, Aug 17, 2018.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I've encountered a weird issue with AssetBundles and sprites. For some reason sprites that are stored like this:
    ScriptableObject
    |____________Sprite (Reference)

    Are not getting loaded properly. Their name is displayed correctly, when used in game, but the sprite itself is white (null) and missing material as well.

    Does anyone know what can be the cause of this?
    Asset Bundle Browser shows they're bundled properly, and included in the asset bundle.

    This is on Unity v.2017.3.1f1.
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Seems like the texture from the loaded sprite is missing. Can't figure out why.
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    After a bit of debugging:
    1. Asset is loaded correctly from AssetBundle;
    2. Afterwards AssetBundle is unloaded with Unload(false);
    3. Asset added to some collection (Dictionary);
    4. Scene transition occurs, dictionary is intact, assets & textures are correct; (Debug outputted from OnSceneLoaded)
    5. Nothing modifies the collection;
    5. Accessing Dictionary with loaded assets -> Assets texture is missing.

    Why?
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Literally, one second after OnSceneLoaded and the resource is gone. I've added coroutine with the yield, inside OnSceneLoaded.

    Does SceneManager also unloads asset bundle resources that are marked with Unload(false) what the F*** is this?

    Edit: Tested without unloading asset bundle, same result.
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Okay, found out the reason. It's freaking Sprite Atlases, that doesn't properly serialize / deserialize via Asset Bundles.
     
    Last edited: Aug 20, 2018
  6. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    If you are using the SpriteAtlas Asset type, make sure you have "Include in Build" checked true. This makes the Sprite contain a reference to the SpriteAtlas that it needs.
     
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    It was already on by default.
     
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Legacy Sprite Atlas works just fine though. So I guess, it's better to stick with it for a while.