Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice
  2. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

Bug Addressables.ResourceLocators sometimes takes a long time to get (20+ seconds)

Discussion in 'Addressables' started by khan-amil, Jun 3, 2021.

  1. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    164
    We're checking Addressables.ResourceLocators at start to get some list of data we'll load later on.
    Recently we've bumped our addressables asset and seen the editor hang at start for 30+ seconds, and found that it was on this line.

    Is there something we could do to prevent that, or is this purely a bug in the addressable system?

    Clearing the built addressables in the editor makes it much less likely to happen, which feels a bit weird as we're using the "fast" mode, it doesn't seem like the built state and cache of addressables should have any impact.

    EDIT :
    On further analysis it's not the ResourceLocator that takes time in itself, but rather getting the keys out of it.
    We get a AddressableAssetSettingsLocator out of the locator, and the Keys propery seems to do big stuff, still don't get why the time to get it is variable from one run to the other though.
     
    Last edited: Jun 3, 2021
  2. SleepyAgapornis

    SleepyAgapornis

    Joined:
    Sep 7, 2018
    Posts:
    23
    man, I'm experiencing the same thing... a lot of times before hitting the play button on the editor, the system hangs with a black screen for around 20 seconds... I didn't know what was causing this, I thought it was another implementation.. but now that I read this, I'm using Addressables.LoadResourceLocationsAsync at start and this also started to happen after I've updated to 1.18.4...
     
  3. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    1,179
    I've noticed issues after the latest auto-update (from 1.17.17 to newer one) when I updated the Editor from 2021.2.0a17 to 0a19 yesterday. It took a while to work out it was the Addressables at the root of it.. random new errors mostly null references. I can't focus on digging further right now but maybe it helps someone to mention that after switching back to 1.17.17 everything seems to be working great again (including with 2021.2.0a19).
     
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,698
  5. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    1,179
    Thanks for giving this attention. I just updated to 1.18.4 again - I can add for now that on the WebGL platform (the only one I tested.. mostly to confirm I wasn't mistaken), in 2021.2.0a19 for Windows 10 using latest version of URP, the following is happening for me.

    1.18.4
    - it works in a build in the browser.
    - in Play Mode with "Use Asset Database" selected for Play Mode Script, there's null references happening where there aren't any with Addressables 1.17.17. At the time they happen, the application shouldn't have got that far into initialization unless the prefab the null ref relates to was successfully loaded. I would have to confirm that though.
    - in Play Mode with "Simulate Groups", there are no exceptions before or while it loads [an addressable prefab].. but it hangs forever at 100% and my first assumption right now would be that IsDone never returns true or something else related to loading.. when exiting Play Mode after waiting a minute with nothing happening, there's an exception raised by the OnDestroy of a component on an addressable, about a null reference of something that's assigned in Start of the same object (..and the reference isn't to a MonoBehaviour / should be able to rule out it just becoming null due to being destroyed by being in the scene at exit).
    - in Play Mode with "Use Existing Build", almost every material is pink and also have null refs on addressables that are usually loaded.

    1.17.17
    - it works in the browser.
    - it works with "Use Asset Database".
    - hangs with "Simulate Groups" but no exceptions when exiting Play Mode.
    - with "Use Existing Build", some prefabs load in but others don't and most materials are pink, including the sky.

    All I can think for now is that maybe there was a change to something about retrieving the names of addressables / reading IResourceLocator .Keys ? What's the official/recommended way to retrieve/iterate all names of Addressables, and could anything (setting, etc.) automatically change what's retrieved at runtime to something other than the Addressable Name they're assigned in the editor..?

    After the next Addressables update is available, if the primary issue persists (i.e. unusable in Play Mode vs. 1.17.17 being great) I'll dig further. Hopefully someone else has more to add. I'm personally fine with using the latest version that works in builds and with "Use Asset Database" for Play Mode Script. I'm wondering if I've just done something non-standard somewhere, especially now I see there's issues in other modes and I remember there was a time they all worked.. just can't remember when since it's been ages since I've selected anything but "Use Asset Database."
     
  6. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    1,179
    I found it! A significant difference between 1.18.4 vs. 1.17.17 that's breaking things.

    Awake is now being called on prefabs that are downloaded via Addressables.LoadAssetAsync even though they haven't been instantiated to the scene. They don't even exist in the Hierarchy but they've now had Awake called by:
    Code (CSharp):
    1. UnityEngine.ResourceManagement.Util.DelayedActionManager:LateUpdate () (at Library/PackageCache/com.unity.addressables@1.18.4/Runtime/ResourceManager/Util/DelayedActionManager.cs:159)
    Adding a Debug.Log("awake", this); to Awake() of the prefab's component outputs it to console and clicking that output selects nothing in the Hierarchy. OnDestroy is being called on this object when the scene is disposed, which is proper behaviour if Awake was called, just that in my case since I only Instantiate this particular object exactly once to an active parent and Start is always called.. I get a cascade of errors by having more than 1 of something I use as a singleton being previously instantiated automatically somehow after download (only in 1.18.4).

    Also to follow up on my previous post with my results of digging further into other stuff I mentioned.. I was able to confirm there's no problem with the addressable names being different somehow or missing, there's the same number of them and they can be downloaded. The pink materials appear to be ones that have references within loaded addressable prefabs (as opposed to being on objects in the scene hierarchy itself), but I didn't spend any time to confirm that. The skybox for me is likely pink because I have a skybox material in a prefab which I set via
    RenderSettings.skybox = skyboxMaterial;
    , and the other pink materials are probably also ones being set or instantiated procedurally from said references to renderers.
     
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,176
    I'm unable to reproduce this with Unity 2019.4.20f1 and Addressables 1.18.4. I think it would be really helpful if you could submit a bug-report with a project that can be used to reproduce it, since the issue does not seem to reproduce easily.
     
    TreyK-47 and polemical like this.
  8. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    1,179
    Well it was good of you to try - this is effectively solved for me, for now (..by sticking to 1.17.17). The purpose of the previous posts was for anyone working on the issues to have additional leads as other bug reports and complaints come in. In my particular project (which is currently in 2021.2.0a19) upgrading to 1.18.4 makes Play Mode unusable due to the difference. I can switch back and forth all day and every time, 1.17.17 is perfect and 1.18.4 it's broken. That's about as much as I can contribute to the cause for the moment. As for the other "Play Mode Script" settings having issues with my particular project, I don't mind either because I don't use them.. maybe it's all working perfectly for everyone else until some particular combination of particular options and particular server and so on :)
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,176
    That's what I think so too.
     
  10. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    1,179
    It's been fixed in 1.18.9!

    I actually just figured out how to get Play Mode working for 1.18.4, it's interesting because it shouldn't work. Instead of instantiating a downloaded prefab, in 1.18.4 you just call .SetParent on the transform to add it to the scene. Any time except with 1.18.4 specifically, doing this results in the error:
    Code (CSharp):
    1. Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'name').
    2. UnityEngine.Transform:SetParent (UnityEngine.Transform)
    I guess it's useless to mention since it's fixed now, but whatever - thank you to whoever resolved it! :D
     
unityunity