Forum rules - please read before posting.

How to add proper fade effects during Adventure Creator → Naninovel transitions?

Hey there! I'm running into a really frustrating camera switching problem and could use some help.
I'm working with Adventure Creator and Naninovel, and whenever I transition from AC to Naninovel (using the action to play scripts with camera swapping), I keep getting this annoying visual glitch. For just a frame or two, you can see parts of the 3D world that players shouldn't see because the cameras haven't moved to their correct positions yet.
I've tried a bunch of different approaches to fix this, but nothing's worked so far. What I'm wondering is if there's a way to code in a complete screen fadeout during the transition, and then only fade back in once the Naninovel camera is properly positioned. That way players wouldn't see those awkward in-between frames.
Has anyone dealt with something similar or have ideas on how to implement this kind of timing with the fade effects?

This is the action code:

using UnityEngine;
using Naninovel;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{
    [System.Serializable]
    public class ActionPlayNaninovelScript : Action
    {
        public string ScriptName = string.Empty;
        public string Label = string.Empty;
        public bool TurnOffAC = true;
        public bool SwapCameras = true;

        private bool asyncCompleted;

        public ActionPlayNaninovelScript ()
        {
            isDisplayed = true;
            category = ActionCategory.Custom;
            title = "Play Naninovel Script";
            description = "Turn off AC (optionally), initialize Naninovel engine (if necessary) and play a Naninovel script with the specified name.";
        }

        public override float Run ()
        {
            if (!isRunning)
            {
                asyncCompleted = false;
                isRunning = true;
                RunAsync();
            }
            else if (asyncCompleted)
            {
                isRunning = false;
                return 0f;
            }

            return defaultPauseTime;
        }

        public override void Skip ()
        {
            /*
             * This function is called when the Action is skipped, as a
             * result of the player invoking the "EndCutscene" input.
             * 
             * It should perform the instructions of the Action instantly -
             * regardless of whether or not the Action itself has been run
             * normally yet.  If this method is left blank, then skipping
             * the Action will have no effect.  If this method is removed,
             * or if the Run() method call is left below, then skipping the
             * Action will cause it to run itself as normal.
             */

            Run();
        }

        #if UNITY_EDITOR

        public override void ShowGUI ()
        {
            ScriptName = EditorGUILayout.TextField(new GUIContent("Script Name:", "Name of the Naninovel script to play."), ScriptName);
            Label = EditorGUILayout.TextField(new GUIContent("Label (optional):", "Label inside the specified Naninovel script from which to start playing (optional)."), Label);
            TurnOffAC = EditorGUILayout.Toggle(new GUIContent("Turn OFF AC:", "Whether to turn off (disable) Adventure Creator before playing the script. You can use @turnOnAC Naninovel command to enable it again from a Naninovel script."), TurnOffAC);
            SwapCameras = EditorGUILayout.Toggle(new GUIContent("Swap Cameras:", "Whether to disable Adventure Creator's main camera and enable Naninovel's camera."), SwapCameras);

            AfterRunningOption();
        }

        public override string SetLabel () => $"{(TurnOffAC ? "Turn off AC" : string.Empty)}, initialize Naninovel engine (if necessary) and play a `{ScriptName}` Naninovel script{(string.IsNullOrWhiteSpace(Label) ? string.Empty : $"starting at `{Label}` label")}.";

        #endif

        private async void RunAsync ()
        {
            if (string.IsNullOrWhiteSpace(ScriptName))
            {
                Debug.LogError("Can't run Naninovel script from AC action: script name is not specified.");
                asyncCompleted = true;
                return;
            }

            if (TurnOffAC)
                KickStarter.TurnOffAC();

            if (!Engine.Initialized)
                await RuntimeInitializer.InitializeAsync();

            if (SwapCameras)
            {
                KickStarter.mainCamera.enabled = false;
                Engine.GetService<CameraManager>().Camera.enabled = true;
            }

            await Engine.GetService<ScriptPlayer>().PreloadAndPlayAsync(ScriptName, label: Label);

            asyncCompleted = true;
        }
    }
}

Comments

  • Instead of immediately disabling the AC MainCamera, you can call its FadeOut function to have it fade to black. Though, even if you set a transition of zero, you'll still need to hold off turning off AC until you later disable the camera / enable that of Naninovel.

  • The issue I'm facing is that the NN runs automatically on its own, which means NNCamera is turned on by default from the start. Because of this, there's always a brief moment where the glitch is visible for a few frames before my code has a chance to reposition the camera to the correct location.

    I've tried working around this by adding a Canvas Group and setting the alpha to black to mask the initial frames, but unfortunately the glitch still bleeds through and remains visible. It seems like the rendering happens before the masking can take effect, so I'm still stuck with this unwanted visual artifact during initialization.

  • edited June 11

    Is it possible to run a Camera: Fade Action to fade out completely before NN kicks in?

  • I have managed to simulate a bit the effect of playing a black background just before returning the control to AC. It seems to work.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.