Search Unity

Shader references disappear when released

Discussion in 'Addressables' started by Paul_H23, Aug 13, 2019.

  1. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    9
    I've got a (another) weird problem with AddressableAssets. I rebuilt my system to load everything, literally everything, as AssetReferences, as having a mixture of references and resources was far too unreliable and unpredictable, especially when working with ScriptableObjects. All seems to work at first, however I have a problem when resetting my game.

    I build the level from assets that are loaded via InstantiateAsync, and I record the GameObject that is returned in an internal data table. These assets don't exist in the scene at start, they are only loaded when needed by the level. Additionally, the main scene itself is addressable and loaded via an empty bootstrap scene. First run, everything works fine, but if I reset at any time, a process that involves calling ReleaseInstance on all the objects that were previously loaded with InstantiateAsync, and then execute the exact same level build process again, once again using InstantiateAsync, all my loaded prefabs are missing their shaders and therefore come out pink.

    I'm presuming the shaders are getting unloaded when all uses are released, however, I have all these shaders in the "Always Include Shaders" list in player settings. I know that if I don't call ReleaseInstance on all the objects I've created, and just instead call InstantiateAsync it all works (apart from doubling the number of objects in the scene of course). Can someone confirm that this is expected behaviour, and if so, how can I either ensure that the shaders remain in memory on release, or are loaded properly (if that's even possible) when a new InstantiateAsync is called.


    Paul
     
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    you presume correctly, it is a known and soon-to-be fixed bug.

    the core issue was that those prefabs of yours weren't actually leaving memory (because something else in their bundle was still ref-counted, see https://docs.unity3d.com/Packages/c.../MemoryManagement.html#when-is-memory-cleared). The prefabs stayed in memory, but the shaders didn't. Unity couldn't handle "reloading" a prefab it knew was still in memory. In the next release, we've adjusted our ref-counting system to handle this.

    1.1.8 (or 9, or 10) should be out next week-ish. just look for this in the changelog:

    • Fixed issue around assets losing dependencies when unloaded then reloaded. This would manifest most often as sprites losing their texture or prefabs losing their shader/material/texture.
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    740
  4. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    9
    Great, thanks, good to know it wasn't me doing something stupid :).

    I have a workaround for now, I just have a "TileManager" that does a "InstantiateAsync" on all the addressables that are labelled "Tile" and remains hidden. As soon as the fix is out I can just remove that functionality and everything should work properly.


    Paul