Search Unity

Time to load an Empty Scene increases based on contents of the group

Discussion in 'Addressables' started by diesoftgames, Jul 2, 2021.

  1. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    This seems to only impact the very first call of LoadSceneAsync(), but if I load an empty scene that is part of a relatively empty group first, it will take about ~0.025s. Now if I move a scene with heavy dependencies into that group, I can increase that first load to ~1.5s (still just loading an empty scene). This is all after making sure I've waited for Addressables.InitializeAsync() to complete before attempting to load anything. But if rather than moving heavy scene dependencies into the group, I just move those same dependencies into the group as a GameObject/Prefab (the scene just uses this prefab as the only object in it), that first empty scene load does not increase.

    So my guess at what's happening (since I think this may also be happening with GameObjects loaded) is that the first load of any given type is affected by all of the addressables in that group of the same type.

    Also I think it's worth noting that the amount of slowdown becomes VERY significant on other, slower devices, in a way that I think scales based on CPU rather than disk speed. So on another device, I can instead see the speed go from ~1.5s to ~30s to load the first empty scene based on the addressables group. After that, loads of even fairly dependent heavy scenes will only take fractions of a second to maybe maxing out at 10s with about as many heavy dependencies as I have anywhere in my game.

    TLDR; I think there's some sort of Addressables per-entry-type CPU bound initialization work going on when I load something of that type for the first time, and it can go from relatively unnoticeable on one (fast) device to complete deal breaker on another (slower) device.

    Details: Unity 2020.3.9f1, LZ4 Compression on addressable groups
    NOTE: The dependencies I'm bringing in to increase the size of a group do include TextMeshPro labels, which I know references /Resources files, so perhaps that is relevant?

    EDIT: I've proved out I see the same thing with Prefabs that I'm seeing with scenes.
     
    Last edited: Jul 2, 2021
  2. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I've essentially solved this for my use case: this time seems to be directly correlated with how many non-addressable asset dependencies I have in other addressable assets of the same group and same type. So for example: in my default group, if I add a scene which has a whole lot of dependencies, most of which are not marked as addressable, my very first scene load (not even of that particular scene) will take about 100-150x longer than it should. If I go through and make sure to include all of the dependencies in the addressables group, that first load then is only taking about 2-5x longer than it should (perhaps I missed some dependencies in there still).

    So I think I'm all set in terms of getting around this problem, but fwiw this was a surprising way for this problem to manifest even though I knew it was best practice to get all your deps of your addressable assets into Addressables even if you're not loading them directly via Addressables. I think I certainly would have understood this problem much sooner if it manifested when I loaded the the addressable asset that had all the dependencies.