I find the documentation to be very lacking on this topic.
I am trying to pre-load scenes additively for performance-related issues (I am building an XR app, and don't want hiccups to happen when transitioning scenes).
The documentation states that Unity 'Stops Progress at Unity stops progress at 0.9'
But what does that even mean?
Have all assets fully finished loading? Is the 0.9 just an arbitrary number? What happens in the last 10%?
Furthermore, the docs state:
//Begin to load the Scene you specify
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Scene3");
//Don't let the Scene activate until you allow it to
asyncOperation.allowSceneActivation = false;
So now I have to store this AsyncOperation, which seems to be a very generic name. Why does it 'magically' have a allowSceneActivation property?
Why is there nothing other in the docs that describes that this has to do with Scene loading?
The way I'm currently doing things feels needleslly complicated:
private void LoadModule(GameplayModuleData startingModule, UnityEvent sceneReadyEvent = null, UnityEvent sceneActivatedEvent = null)
{
Logger.Log($"Loading Module: '{startingModule.name}'");
SceneLoadState sceneLoadState = ModuleLoader.Instance.LoadModule(
startingModule,
additive: true,
preload: true,
sceneReadyEvent,
sceneActivatedEvent);
_loadedModules[startingModule] = sceneLoadState;
Logger.Log($"Tuple stored for module '{startingModule.name}'");
}
void Update()
{
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
Logger.Log($"Activating scene for Starting Module: '{StartingModule.name}'");
_loadedModules[StartingModule].SceneLoadOperation.allowSceneActivation = true;
}
}