Async loading of levels causes lag spike in open world scenes

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?

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?

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