Creating a fade out and in transition for loading. Functions not executing in order.

I have a custom scene management system, and when it switches scenes I want it to fade out and fade back in once the scene has loaded.
If the scene is a Map Scene, load times can take 3-4 seconds as it creates all the tiles needed.
However, at the moment, it’s like it freezes the games for a few seconds and jumps to the map scene without any transition at all.

Here’s my code for scene changes:

public void ChangeScene(rpg_Scene _scene)
        {
            StartCoroutine(transition.FadeToBlack());
            currScene.OnClose();
            
            if (scenes[scenes.Count - 1] is rpg_MapScene)
            {

            }
            else
                scenes.RemoveAt(scenes.Count - 1);
            
            scenes.Add(_scene);
            currScene = scenes[scenes.Count - 1];
            currScene.OnLoad();
            StartCoroutine(transition.FadeFromBlack());
        }

I don’t think Coroutines will work here.


In my game which is a VR game where framerate is very important I do all the fade in/out before loading the scene, controlled from global code that always runs (DoNotDestroyOnLoad Game Manager). Have it all black while things in loading can affect your framerate, make it stutter. Then transition back in using a transparent cube around the camera (from my game controller). It makes no difference if you use LoadScene or LoadSceneAsync, it will always stutter.


I use one game manager, that has one main camera, that has one transparent cube around it. But maybe it can be set up different ways. This way at least you will not be without main camera some frames during scene transitions that can happen otherwise.


Here is some code, just run UpdateFade(); every update from the GM: galaxyvr/Assets/C#/GameManager.cs at quest · rh-galaxy/galaxyvr · GitHub