Search Unity

Textures are referenced after asset release

Discussion in 'Addressables' started by Hostur, Oct 16, 2018.

  1. Hostur

    Hostur

    Joined:
    Jul 6, 2015
    Posts:
    60
    Hi,
    If I load prefab from the addressables, and that prefabs material require texture this texture is loaded to the memory.
    When I unload this prefab texture remain loaded with reference to non-existing object.
    Easy to check in develop build with attached profiler.

    No matter if textures/materials are in the addressables too.

    I reported it but Unity reports are good for linux users for whom time have no value :)
    Is there any correct option for unloading referenced textures or it is just a bug?
     
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    You need to call Resources.UnloadUnusedAssets() for unloading not directly loaded assets (ex, texture or mesh which is referenced from prefab). Addressables only address directly loaded assets.
     
  3. Hostur

    Hostur

    Joined:
    Jul 6, 2015
    Posts:
    60
    It doesn't work because this texture have a fake reference. I'm releasing instance (if exists), loaded asset, assign null to asset and instance(if exists) and call unloadunusedassets().

    The only think that works for me is to find this texture by hand and call destroy on it but than I can't load it again.
     
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Two general notes: Addressables uses the standard loading/unloading path fro assets in bundles. Second, you should generally try to avoid using UnloadUnusedAssets as it usually causes performance hits.

    Now, specific to this...
    I'm guessing you're loading a prefab that does not actually connect down to a texture, then using addressables to load a texture and set it in that prefab? Assuming I understand correctly, then that texture will not be unloaded unless you release it. ALL load/instantiate calls need to be paired with a release. Addressables does ref-counting, and will hold on to anything that doesn't get it's count released back to 0.

    Let me know if I'm misunderstanding.

    -Bill
     
  5. Hostur

    Hostur

    Joined:
    Jul 6, 2015
    Posts:
    60
    Hi Bill,
    As simple as possible:
    In empty project create a cube.
    Create a material for that cube.
    Add any texture to the project and add it to this material albedo.

    Create a prefab from this cube and add it to any addressables group.
    Load this prefab from addressables and unload it.
    You can also instantiate it and release instance and also release asset as self - doesn't matter texture will reamin in memory forever. I reported it (1083257).
    I tried to put material and texture in addressables too but it changed nothing.
    Check in memory profiler snapshot on build
     
    5argon likes this.
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for the simplified description. We are looking into that ticket.

    -Bill
     
  7. Suvitruf

    Suvitruf

    Joined:
    Sep 3, 2014
    Posts:
    39
    Hello there. Any updates? Still happens in 1.6.2
     
  8. Jalict

    Jalict

    Joined:
    Nov 3, 2014
    Posts:
    20
    Also interested in this case. What would be the best practice here?
     
    vikchokov likes this.
  9. bagelbaker

    bagelbaker

    Joined:
    Jun 5, 2017
    Posts:
    67
    Any update on this issue? I'm on 1.6.0 and running into what seems to be the same problem.
     
    vikchokov and Suvitruf like this.
  10. achatsUnityLS

    achatsUnityLS

    Joined:
    Apr 1, 2020
    Posts:
    1
    Any update ?
     
    vikchokov likes this.
  11. Krnitheesh16

    Krnitheesh16

    Joined:
    Apr 22, 2020
    Posts:
    14
    Any Update?
     
    vikchokov likes this.