Search Unity

How to avoid using Resources.UnloadUnusedAssets() for dynamically unloaded scenes.

Discussion in 'World Building' started by Kichang-Kim, Aug 26, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi. I'm working on large-scene streaming system for my project, and stuck in memory management.

    In detail, my system loads and unloads subscene dynamically based on player's position, and the system call Resources.UnloadUnusedAssets() after scene unloaded for clearing memory. But I found that calling Resources.UnloadUnusedAssets() makes huge spike.

    With some investigation, this issue can be solved by manually releasing referenced assets (
    )

    But the problem is that some assets are referenced over the multiple scenes (+ other script!), and hard to extracts only "unused asests".

    So, my question is that:
    1. How to get asset list which is referenced by specific scene?
    2. How to unload "not used assets" without calling UnloadUnusedAssets()?, especially after scene unloaded.

    Thanks.
     
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Also, if I manage manually my assets, what assets should be destroyed manually?

    Texture, Material, Shader, Mesh, AnimationClip, AnimationRuntimeController ...

    Any other assets?
     
  3. Basti_TinyRoar

    Basti_TinyRoar

    Joined:
    Oct 4, 2016
    Posts:
    11
    Hello!
    Did you find a solution for that problem? I also need to avoid unload unused assets.
     
  4. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
  5. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    I have implemented my own asset management system, which tracking all references for trackable assets. For this, I should add my management component to all of my MeshRenderer, SkinnedMeshRenderer, AudioSource and so on.
     
  6. Basti_TinyRoar

    Basti_TinyRoar

    Joined:
    Oct 4, 2016
    Posts:
    11
    Thanks for your replies!
    I have looked into addressables system but for example meshes in scenes didnt get unloaded automatically as I expected. We now also looked into making an own system that unloads them.
     
    NotaNaN likes this.