Search Unity

Resources.UnloadAsset in standalone player

Discussion in 'Scripting' started by MuseGames, Mar 28, 2016.

  1. MuseGames

    MuseGames

    Joined:
    Mar 19, 2008
    Posts:
    98
    I'm having some issues using Resources.UnloadAsset() that only manifest in a built player - not in the editor. That alone convinced me there's a bug in Unity at work, which for the record I've submitted as case #782420. In the meantime - has anyone else run into this, or found a reasonable workaround or way of getting equivalent functionality?

    The issue, pared down to the repro case I submitted:

    1) I additively load a scene containing one GameObject, which in turn has one script that references a bunch of textures.
    2) The textures I'm not going to use immediately, I call Resources.UnloadAsset() on.
    3) Later, assign one or more of the unloaded textures to a material for rendering.

    The expected behavior - and it works this way in the Editor - is that UnloadAsset() removes the texture from RAM until it is actually used, at which point it silently loads it back in. However, in (Windows, 32- or 64-bit) standalone builds, the silent re-load never occurs, and I'm left with a texture reference that acts like null. This used to work just fine - we ship a game built on 4.6.6 that relies on this functionality for managing certain UI assets - but fails in both 5.2.4 and 5.3.4.