Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[bug] addressables save utility object ("ResourceManagerCallbacks") in scene and it leaks after that

Discussion in 'Addressables' started by nik_d, Aug 16, 2019.

  1. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    66
    Addressables don't even try to reuse already created ResourceManagerCallbacks and artists don't notice them, so it became there are a lot of them in scenes.

    Even worse - if this object is saved in scene, because of DontDestroyOnLoad in MonoBehaviourCallbackHooks, they leak!

    workaround: in Runtime\ResourceManager\ResourceManager.cs
    after line:

    m_CallbackHooks = new GameObject("ResourceManagerCallbacks", typeof(MonoBehaviourCallbackHooks)).GetComponent<MonoBehaviourCallbackHooks>();

    put:

    m_CallbackHooks.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; //**addressables: we don't need the utility object to be saved in scene //todo: cleanup current scenes
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    thanks, we'll look into it.
     
  3. StupydHors

    StupydHors

    Joined:
    Oct 25, 2016
    Posts:
    25

    Thanks just what I needed. Maybe its hidden in a DLL or something (should not be because addresables are supposed to be open source) but I noticed the Dispose method in ResourceManager.cs has 0 usages.
     
  4. Egil-Sandfeld

    Egil-Sandfeld

    Joined:
    Oct 8, 2012
    Posts:
    72
    Still getting these after runtime in editor:

     
    Brightori, hololabs and Lukas-Labaj like this.
  5. paladinrose

    paladinrose

    Joined:
    Aug 1, 2010
    Posts:
    11
    Also getting these objects after asset database is updated.
     
  6. Egil-Sandfeld

    Egil-Sandfeld

    Joined:
    Oct 8, 2012
    Posts:
    72
    Below does NOT work unfortunately...

    ---

    Still getting this error with Addressables 1.7.4, but I think I've found a workaround, to prevent these gameobjects from being added:

     
    Last edited: Apr 3, 2020
  7. ruiyl

    ruiyl

    Joined:
    Aug 4, 2019
    Posts:
    20
    I just did what you suggest there @Egil-Sandfeld . The objects still popped up in 1.7.5.
     
  8. Egil-Sandfeld

    Egil-Sandfeld

    Joined:
    Oct 8, 2012
    Posts:
    72
    Yeah, sorry that didn't work unfortunately. Also got it myself just now
     
  9. ruiyl

    ruiyl

    Joined:
    Aug 4, 2019
    Posts:
    20
    Let's hope they will fix this in the next update!
     
  10. Patrick_PS

    Patrick_PS

    Joined:
    Sep 9, 2019
    Posts:
    154
    I had this when I tried to load assets with addressables in an editor script.
     
  11. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    This is still an issue in Unity 2019.3.8f1. GameObjects are instantiated into the scene at edit time, although they should be part of DontDestroyOnLoad at runtime only.
     
  12. VacuumBreather

    VacuumBreather

    Joined:
    Oct 30, 2013
    Posts:
    68
    Still an issue. Basically renders this package unusable. It's trashing every scene
     
  13. peartreegames

    peartreegames

    Joined:
    Mar 15, 2016
    Posts:
    8
    I was also experiencing this issue in editor. I couldn't find any uses of Dispose as GrandBOOM mentioned (except for a couple test clean ups) but also couldn't quite find where it should be called, maybe someone smarter than me can see. So for now as a quick patch I've just added scene search in the ResourceManager RegisterForCallbacks function.

    m_CallbackHooks = GameObject.FindObjectOfType<MonoBehaviourCallbackHooks>();

    The function now just looks like this:

    Code (CSharp):
    1.        
    2.         private void RegisterForCallbacks()
    3.         {
    4.             m_CallbackHooks = GameObject.FindObjectOfType<MonoBehaviourCallbackHooks>();
    5.             if (CallbackHooksEnabled && m_CallbackHooks == null)
    6.             {
    7.                 m_CallbackHooks = new GameObject("ResourceManagerCallbacks", typeof(MonoBehaviourCallbackHooks)).GetComponent<MonoBehaviourCallbackHooks>();
    8.                 m_CallbackHooks.OnUpdateDelegate += Update;
    9.             }
    10.         }
     
    lanpartygamesstudio likes this.
  14. Brightori

    Brightori

    Joined:
    Sep 15, 2017
    Posts:
    64
    have same problem =(
     
  15. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    We're seeing this, too.
     
    lanpartygamesstudio likes this.
  16. lanpartygamesstudio

    lanpartygamesstudio

    Joined:
    Jul 3, 2019
    Posts:
    3
    I am observing this as well, seems like the only place where the OnUpdateDelegate (funny name for an event) event gets unsubscribed is from here:
    upload_2020-7-1_13-45-11.png

    However I believe every time a new Load operation is initiated, a subscriber is added from RegisterForCallbacks. Which leads to a huge leak of delegates:

    upload_2020-7-1_13-43-11.png

    Unless I am misusing the whole system, I think this should be fixed...

    EDIT: I'm testing a simple fix and seems to be working fine (might have side effects since I'm not aware 100% of the rest of the system but seems reasonable)

    upload_2020-7-1_14-8-24.png
     
    Last edited: Jul 1, 2020
  17. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    Unity -- is this on your radar to get fixed? ETA on a fix?

    It's definitely still a bug we're seeing frequently, and from @lanpartygamesstudio posted code changes it would seem that the problem/cause of the issue is spelled out pretty well.
     
    lanpartygamesstudio likes this.
  18. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    It has been an entire year, and ResourceManagerCallback's still leaks in to the scene.

    And whats hilarious is that sometimes this is the thing that causes our scenes to become dirty, so when we do addressable update builds the scene needs to be rebuilt and re-downloaded by the end user because of this garbage that is being leaked into the scene. So it is screwing over your own pipelining.
     
  19. Danoli3

    Danoli3

    Joined:
    Sep 12, 2017
    Posts:
    14
    How was this fix missing from 1.8.5...
     
    lanpartygamesstudio likes this.
  20. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
  21. Thomas_Rasor

    Thomas_Rasor

    Joined:
    Aug 1, 2015
    Posts:
    3
    extra bump. really obnoxious
     
  22. Batka

    Batka

    Joined:
    May 23, 2016
    Posts:
    22
    This way I don't end up with lots of them, only one persists.

    Based on OP idea

    Code (CSharp):
    1. internal class MonoBehaviourCallbackHooks : MonoBehaviour
    2. {
    3.     public event Action<float> OnUpdateDelegate;
    4.  
    5.     void Awake()
    6.     {
    7.         hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
    8.         DontDestroyOnLoad(gameObject);
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         if (OnUpdateDelegate != null)
    15.             OnUpdateDelegate(Time.unscaledDeltaTime);
    16.     }
    17. }
    18.  
     
  23. Katoha

    Katoha

    Joined:
    Feb 17, 2020
    Posts:
    5
    Wow, this is sure painful, it is affecting my tests which get slower and slower as these leak
     
  24. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,816
    Let me flag this for the team, and pass along any update they might have.
     
  25. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    762
    Hey all, sorry about this. I thought this had been fixed already. If you're on a version older than 1.16.X try updating and see if the issue still persists. I'll track down what happened to our ticket or make a new one if I can't find anything.
     
  26. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    762
    So, I just found the PR where this issue should be fixed. Make sure you're on 1.16+ (1.16.15 is the newest at the time of writing). If the issue persists after updating please report a bug.