Search Unity

My models initiates failed with Addressables.Release

Discussion in 'Addressables' started by shibi2017, Sep 10, 2019.

  1. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    I use Addressables.LoadAssetAsync<>() to load some assets in project, and the first time i run the .exe I found that the memory usage increasing gradually, and finally the fps start to become lower and lower due to the memory usage get full.
    so I use Addressables.Release<>() in the code after i initiate the instance of models.
    but when i build it, run the .exe, my models didn't load in the scene.

    And if I delete the Addressables.Release<>() , the models loading success.

    Do anyone meet this problem? And I can't find the solution. thank you for your help.
    btw, English is not my first language, if you get any inconvenient to understand this question, feel free to ask me.

    Code (CSharp):
    1.         Addressables.LoadAssetAsync<PointCache>(PointCache).Completed += op =>
    2.         {
    3.             GameObject plant = new GameObject();
    4.  
    5.             PointCachePlayer player = plant.AddComponent<PointCachePlayer>();
    6.  
    7.             player.pointCache = op.Result;
    8.  
    9.             player.Init();
    10.  
    11.             Addressables.Release<PointCache>(op.Result);
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Just curious is the PointCache a ScriptableObject?

    Anyway, you can not release the asset loaded (by LoadAssetAsync) immediately after assigning it to some reference. You should release the asset when you don't need it anymore. In your case, after player object get destroyed.

    Your description sounds like a memory leaking, but it's hard to guess without further information. Maybe you can try running in editor with profile enabled first.
     
  3. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    and in the editor there is nothing worng. It can be load in the play mode, but when i build up a .exe, it does not work.
    and I just try to delay the relase function. by 10 seconds delay call the Release, it seems goes well.
     
  4. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    and do you know how to listen the loading process is done? sometimes I use the asset after load it, but the console said : null pointer exception ... tell me i haven't create the object.

    thank you again!
     
  5. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    PointCache is a Component in the plugin Vertex animation tool.
    it allows you to add some vertex animation in it and to play them.
     
  6. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    As said, it's not safe to release assets after keep a reference. Weird thing may happen, some type of assets works, others not.

    The loading is done in the complete callback. It should be reliable, but if you find reproduced weird something, please report a bug.

    I don't remember we have the ability to load component directly by LoadAssetsAsync API? I thought it was a feature adding in next release or perhaps to the official sample project. You could search the sub-forum to verify, or maybe my memory is fuzzy.
    Well that may explain some weird thing you're facing to. You load a component from a game object, keep a reference of it, and perhaps released the component or the game object it was attached to. You may want to find a workaround here.
     
    Last edited: Sep 10, 2019
  7. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    We do not yet. It may be added and there is an example that does that through a specialised AssetReference that wraps it. AssetBundles do not allow loading a component directly.
     
    Favo-Yang likes this.