#SceneManager order of operation

68 messages · Page 1 of 1 (latest)

quartz flame
#

When I call SceneManager.LoadGlobalScenes, is there a way to set allowSceneActivation as false and when OnLoadEnd event is triggered, I then do whatever (fade to screen to black) then set allowSceneActivation as true?

I looked at this:
https://fish-networking.gitbook.io/docs/manual/guides/scene-manager/events

But I'm not sure how to do something like:
Main menu -> Fade to black screen -> load the "Scene Loader" scene -> Fade to clear -> Wait until game scene is loaded -> Game scene is loaded -> Fade screen to black -> Unload "Scene Loader" scene -> Activate game scene -> Fade screen to clear

#

Easier reading by numbered list:

  1. Main menu
  2. Fade to black screen
  3. Load the "Scene Loader" scene
  4. Fade to clear
  5. Wait until game scene is loaded
  6. Game scene is loaded but is not activated
  7. Fade screen to black
  8. Unload "Scene Loader" scene
  9. Activate the game scene
  10. Fade screen to clear

That is the process I want to do, but SceneManager seems to auto activate the loaded game .. I need to fade screen to black then activate scene... how?

quartz flame
#

Okay, got everything working except not being able to fade screen to black just before game scene activation.

quartz flame
#

I don't think I'm doing this right. I don't really have a good grasp on how the scene to scene should work with co-op... -- if I do as single player, no fishnet, I got everything exactly what I want, fade to black, etc. etc. But with co-op, I read the documentation and understand the events, but I do not know the correct logic flow in scene loading. Anyone willing to point me to the right direction?

flint bridge
#

Why do you want to wait to set the game scene to active?

flint bridge
#

And that it’s getting unloaded before it’s done fading? What is the exact problem.

quartz flame
#

Correct - fade screen script is on the scene loader. I can move it out. I just want "on scene loaded" then fade to black then activate the game scene. ... then un-fade to clear.

#

In the numbered list above, it's the #7. The problem is as soon as #6 is completed, the game is loaded, it activates that scene immediately

#

I can make a quick video of what I'm trying to accomplish if that helps... I'm much more visual type of a person.

flint bridge
#

So seeing how you did that I don’t see how it can’t carry over to networked scenes

quartz flame
#

Here's a quick code I made which is similar to my old script that worked:

public static IEnumerator LoadSceneAsyncSwitch(string scene)
{
    // We're now showing the "Loading game, please wait..."
    // While showing that, go ahead load the actual game scene...
    // Start loading the game:
    async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene, LoadSceneMode.Single);
    // Tell Unity to not activate the scene
    async.allowSceneActivation = false;

    // The usual
    while (!async.isDone)
    {
        if (async.progress >= 0.9f)
        {
            break;
        }
        yield return null;
    }

    // Game scene is loaded! Now fade the screen to black... and wait until it's done
    yield return StartCoroutine(FadeToBlack());

    // Screen is now black - time to activate the game scene
    async.allowSceneActivation = true;
}```
#

Above is untested - just an example of what I did before that worked well. Now I want to do the same but with Fishnet SceneManagement's event, not sure how to tell it to not activate the scene until after I fade screen to black.

#

Ok lemme see if I can make a video....

flint bridge
#

Okay no this is perfect.

#

So I looked into the code in the scene manager, and the allowSceneActivation is automatically handled by the DefaultSceneProcessor.

#

So you cannot set that manually unless you modify the defaultSceneProcessor to not handle that for you.

#

However the Scene is Activated before OnLoadEnd but After OnLoadPercentage change hits 100%

#

so if you tap into OnLoadPercentage Change and check for when it hits around 90 - 100% you could trigger your fade to black and then fade to clear when OnLoadEnd happens

#

its not the best but alternative would be messing with editing the default scene processor and making it your own.

#

Here is where the Scene activation is Disabled in DefaultSceneProcessor.CS

#

and then here is where it is Activated

quartz flame
#

Yes, that's where I saw it ... I didn't want to edit these scripts because later I might update version to latest... Hmmmmm...

#

But I could modify and make self note to re-modify that after doing an update.

flint bridge
#

Yeah so there is a guide for addressable loading on the Docs that is similar you make your own defaultSceneProcessor, copy all of the code, and then edit what you want and drag that into the scenemanager component on your NetworkManager GameObject.

quartz flame
#

Hmmmmmmmm looks like that's the way it shall be. Okay, I'll do that then.

flint bridge
#

So create a script called MyDefaultSceneProcessor and just Inherit from DefaultSceneProcessor

quartz flame
#

Oooo inherit. Okay cool! 😄 Doing that now as you give guidance. 😄

flint bridge
#

I would also file a suggestion in the github to add support for manually setting the activation of the scene as a default option.

quartz flame
#

Okay I'll do that..... if I know where that is... lemme find and confirm with you.

#

Found github, but not sure where to file a suggestion...

flint bridge
#

yup!

quartz flame
#

Wait a minute... isn't this the same thing?

#

Well... not exactly 100% same though...

flint bridge
#

lol I added that one and its a little different. thats which scene should be the "Active Scene"

#

not "Activating the Scene" during load

quartz flame
#

Oh haha okay alright. I'll go ahead add a new discussion... marking it as feature request somehow... here goes.

flint bridge
#

but for that fix, now thinking it over I dont think you could just create a DefaultSceneProcessor

quartz flame
#

Oh yeah? Hmmm. 👀

flint bridge
#

you may have to do the work arounds, like tapping into the OnLoadPercent event, and triggering the fade to black before it hits 100%

#

I just dont see how you can get reference to the AsyncOperation that you want and call Activate Scene with whats currently available with fishnet, but maybe when @crystal heart gets a minute he might have a solution.

quartz flame
flint bridge
#

Yeah it makes sense I can add some comments later to this as well, but Im trying to see if there is a way to accomplish exactly what you want currently with the cards we are dealt.

quartz flame
#

Much appreciated. Thank you @flint bridge 😄

teal vineBOT
#

Katerlad received thanks.

quartz flame
#

hee hee hee...

flint bridge
#

Okay it looks like according to unity allowSceneActivation = false just stalls the async function at 90% when triggering back to true it loads the remaining 10% of the scene.

quartz flame
#

Oh.

#

Hmm.

#

Well I got excited for a moment there...

flint bridge
#

So in all honestly just triggering what you want to happen at 90% would probably just give you what you want, butt I get the need of wanting the fader to at least go to black before loading the remaining part of the scene.

quartz flame
#

Yeah......... that.

flint bridge
#

couldn't you just have your canvas in the sceneloader script hide whatever is loaded in the background? and then fade to black over that canvas, unload sceneloader and fade to clear to show the new scene?

#

or are you doing something unique?

#

I feel like there are some tricky things you could do to achieve similar results if you think outside the box if this feature is not implemented.

quartz flame
#

We'll see what FirstGearGames says. 🙂

flint bridge
#

yeah I see exactly why you cant do that now haha! looking good btw!

quartz flame
#

Haha, thank you. 😄

flint bridge
#

Hey @quartz flame not sure if you saw the GitHub post for the suggestion, but I messed up and forgot that the default scene processor is a monobehavior but it would be totally possible to do a coroutine before activation by customizing that and referencing your fader before activation.

quartz flame
#

Yeah I've been following on that and have made a copy of default scene processor and was able to do what I wanted.