Page 1 of 2

Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 1:14 am
by AoF
Hello. I have it set up so when I call LoadLevel, it fades out then in. I'd like to be able to run something between it being faded out and before it's faded in. In other words, I want to execute a piece of code when the screen is black. The reason I want to execute this code then is because it changes things visually and I don't want the changes to be visible until the scene fades in.

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 9:11 am
by Tony Li
The LoadLevel() sequencer command calls the C# method SaveSystem.LoadScene() under the hood. This method will use a Scene Transition Manager component if available. The Scene Transition Manager has UnityEvents. You could configure Leave Scene Transition > OnTransitionEnd() to do something, but it would happen every time you change a scene.

Instead, you may want to use the Fade() sequencer command. For example:

Code: Select all

Fade(stay,1);
SetActive(Dr Jekyll, false)@1;
SetActive(Mr Hyde, true)@1;
LoadLevel(London Street)@1;
Fade(in,0)@2
This does the following:
  • At 0:00, fades to black and keeps the black cover in place.
  • At 0:01, deactivates Dr Jekyll and activates Mr Hyde.
  • At 0:01, starts LoadLevel(). Assuming it has a default Scene Transition Manager, it fades out for 1 second, but this isn't visible since the screen is already black from the Fade() command.
  • At 0:02, gets rid of the Fade() command's black cover. The screen is still black from the Scene Transition Manager's black cover.
  • When LoadLevel() has finished loading the new level, the Scene Transition Manager fades in.

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 1:39 pm
by AoF
OK thanks, I'll give that a shot.

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 2:09 pm
by AoF
OK I try that:



Without that required, it stayed black.

This still doesn't work correctly though. I'll show you in a gif (NSFW): https://imgur .com/a/hzR8iCQ

Notice how for a moment it fades back in and lets you see the bathroom again? Why is that happening?

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 2:26 pm
by AoF
Here's something weird: I put all those steps into a custom sequence, and it works as expected:

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    public class SequencerCommandSubtractEnergyAndLoadLevel : SequencerCommand
    {
        public void Start()
        {
            DialogueManager.PlaySequence("Fade(stay,1);");            
            DialogueManager.PlaySequence("SubtractEnergy()@1;");            
            DialogueManager.PlaySequence("LoadLevel(Bedroom)@1;");            
            DialogueManager.PlaySequence("Continue()@1;");            
            DialogueManager.PlaySequence("required Fade(in,1)@2;");            
            Stop();
        }
    }

}

Any idea why that would work correctly but all inlined in the editor works incorrectly?

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 3:06 pm
by Tony Li
The "required" keyword is required because the previous command, Continue()@1, immediately stops the sequence and progresses to the next dialogue node. The "required" keyword allows Fade(in,1)@2 to run even though Continue() ended the sequence at the 1-second mark. However, when required commands are run ahead of time, they're expected to finish immediately so the next dialogue node can run its sequence. Try setting the last command to:

Code: Select all

required Fade(in,0)@2

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 3:08 pm
by AoF
Well, I had that at first, but when I did, the scene didn't fade in, it just immediately showed. For aesthetic reasons, I don't like that. Is there a way to have the best of both worlds?

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 4:23 pm
by Tony Li
Yes. Currently it would be a little messy because it needs to handle the timing of two fades (the Fade() sequencer command and the scene transition manager), some durations of which the game is paused because the scene transition manager's Pause During Transition checkbox is ticked. I'll think it over and come up with a clean solution.

Re: Doing something during LoadLevel while the screen is faded

Posted: Sat Jun 15, 2019 4:39 pm
by AoF
Sounds good, thanks!

I'm spitballing here (let me know if it's unhelpful), but maybe if there was an option to call LoadLevel without fade, that would make this straight forward. Then the only fading would come from the explicit Fade calls.

Re: Doing something during LoadLevel while the screen is faded

Posted: Sun Jun 16, 2019 10:05 pm
by Tony Li
The catch is that you can't use "required Fade(in,2)@2" in combination with "Continue()@2" because the Continue() will kill the Fade() in order to let the next node go.

I ran out of time today, but I'll try to reply with a good, simple answer tomorrow.