Hello!
I’m making a Scene Loader to set up my game from multiple additive scenes, like little components added to the main scene (Lighting Scene, Scenary Scene, Gameplay Scene, etc.). I managed to activate all of them simultaneously, but when they do the Awake and Start methods do not trigger in the correct order. i.e:
Awake and Start from scene 1 are called at frame 4.
Awake and Start from scene 2 are called at frame 5.
And so on…
void Start()
{
LoadScenes(scenesPaths, LoadedAtAwake);
}
void LoadScenes(List<string> paths, LoadSceneCallback callback)
{
_scenesCount = paths.Count;
_loadingScenes = new List<AsyncOperation>();
var activeScenes = GetActiveScenes().Select(scene => scene.path);
// Load all scenes not already active
foreach (var path in paths)
{
if (!activeScenes.Contains(path))
{
AsyncOperation scene = SceneManager.LoadSceneAsync(path, LoadSceneMode.Additive);
scene.allowSceneActivation = false;
_loadingScenes.Add(scene);
StartCoroutine(LoadProgress(scene, callback));
}
}
}
IEnumerator LoadProgress(AsyncOperation scene, LoadSceneCallback callback)
{
// Load the selected scene in additive mode and wait for all scenes to
// be loaded before activating them
// Wait till the magic .9 number when the scene is ready to be loaded
while (scene.progress < 0.9f)
yield return null;
_scenesLoadedAmount++;
if (_scenesLoadedAmount == _scenesCount)
{
// If all scenes are ready to be loaded allow all of them to be loaded.
foreach (var async in _loadingScenes)
async.allowSceneActivation = true;
callback();
}
}
Any ideas if it’s possible to achieve that every Awake get called first and then every Start, once all additive scenes were enabled?