Search Unity

Explicitly freeing referenced blobs (Meshes, Textures) from a complex loaded Prefab

Discussion in 'Asset Bundles' started by ferretnt, Oct 11, 2018.

  1. ferretnt


    Apr 10, 2012
    Is there a way to do C++-style "unload the binary data for this asset and all of its dependencies" without calling Resources.UnloadUnusedAssets?

    Suppose I have a large scrolling carousel of buttons that are async loaded when visible. When on screen, each button calls a load call to load a prefab.

    void Update()
    if (isOnScreen && !loadInitiated)

    (I'm using Resources.Load in this example, but we could easily switch to assetbundles.)

    Now, to get rid of that prefab, which I'm 100% sure it has no external or scene references to it because I just loaded it, what can I do?

    Obviously, I can Resources.UnloadUnusedAssets(). This works, but seems to hitch the app quite badly on mobile.
    I could traverse the loaded object hierarchy and explicitly destroy Meshes and Textures it refers to, which would get most of the memory way?

    Is there a more efficient way to handle this case where I know the root of the object hierarchy I loaded and just want to destroy everything it references that I loaded?
    Last edited: Oct 13, 2018