Search Unity

How to increase reference count for implicitly loaded dependencies?

Discussion in 'Addressables' started by Soniksz, Jan 23, 2020.

  1. Soniksz

    Soniksz

    Joined:
    Jan 23, 2020
    Posts:
    3
    Example:
    Game object A holds normal refrence to game object B.
    A and B are addressables.
    A is loaded by Addressables.LoadAssetAsync() ( B is dependency).
    Let's say i want to unload A by Addressables.Release() but still keep B.
    I don't want to use AssetReference inside A to B because loading is more difficult.
     
  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    AFAIK this is automatic. Since A depends on B, incrementing/decrementing a reference to A should also increment/decrement a reference to B.
     
  3. Soniksz

    Soniksz

    Joined:
    Jan 23, 2020
    Posts:
    3
    Sorry maybe my question isn't clear.
    After loading A i want to spawn some instances of B by Instantitate(B).
    Currently when i unload A with Addresable.Realse(A), all sprites inside B instances are unloaded, so i want to increase explicitly ref count for addressable B.
     
  4. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Use Addressables.InstantiateAsync
     
  5. Soniksz

    Soniksz

    Joined:
    Jan 23, 2020
    Posts:
    3
    I can't use Addressables.InstantiateAsync on B in this case.
     
  6. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    In that case, I think you have to make B its own addressable and instantiate it separately. That way when you load A, it will also load B as a dependency, and when you instantiate B, it will increment its own ref count, so when you unload A, it will decrement B's ref count but not unload it until you release B.