Search Unity

Async loading of levels causes lag spike in open world scenes

Discussion in 'Scripting' started by Zergling103, Apr 12, 2018.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Currently, it appears that if you want to asyncronously load another part of the world, LoadLevelAdditiveAsync will invoke a FindObjectsOfType internally.

    For small scenes this isn't an issue. But in cases where a feature like this would probably have its most value (i.e. open world games), you probably have a lot of objects existing in the scene at once - and in these cases, invoking FindObjectsOfType is B-A-D.

    Yet... LoadLevelAdditiveAsync does just that.

    So lets recap:

    - Open world games need to use LoadLevelAddtiveAsync to load in more of the game world without creating frame rate hitches.
    - Open world games have a lot of objects loaded at once.
    - Calling FindObjectsOfType in a scene with a lot of objects loaded at once creates frame rate hitches.
    - LoadLevelAddtiveAsync calls FindObjectsOfType.

    Therefore:
    - Calling LoadLevelAddtiveAsync in a scene with a lot of objects loaded at once creates frame rate hitches.
    - Calling LoadLevelAddtiveAsync in an open world style game creates frame rate hitches.
    - Open world games have no means to load in more of the game world without creating frame rate hitches.

    Seems like a nasty catch 22. Is the work around to simply not use Unity's level loading features at all? Do we need to load in everything manually, e.g. asset bundle async loading?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    Did you debug this and catch an actual call to the offending FindObjectsOfType()?

    The problem seems possibly more something that happens only in the editor even. Did you try to see if it calls FindObjectsOfType() on a distribution build too?
     
  3. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    A deep profile reveals that Unity itself is calling this method as part of "LoadLevelAddtiveAsync Integration". Could someone at Unity HQ comment out that line so we can async load? xD