Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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 at 12:51 AM