Home > database >  Unity animation doesn't play after transitioning to a new scene
Unity animation doesn't play after transitioning to a new scene

Time:09-24

I would like to play an animation before switching to a new scene, load the scene and then play another animation after that. The code I use for this task is as follows:

    IEnumerator PlayTransitionAndLoadSceneCoro(string sceneName) {
        transition.SetTrigger("Start");
        yield return new WaitForSeconds(transitionTime);

        AsyncOperation asyncSceneLoad = SceneManager.LoadSceneAsync(sceneName);
        while (!asyncSceneLoad.isDone)
            yield return null; // Block execution until the scene is loaded

        transition.SetTrigger("End");
    }

Both scenes use the same TransitionManager prefab, and my animator object is set up as follows: enter image description here

But while the animation plays properly in the first scene, it doesn't play on the new scene (that also has the TransitionManager prefab) as shown in the gif below.

enter image description here

CodePudding user response:

You need to call transition.SetTrigger("End"); in the Start() or Awake() function of next scene.

When you load the next scene, transition.SetTrigger("End"); is never called or just called in the first scene.

  • Related