Changing scenes - FadeIn animation does not work...

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By haha-lolcat1

Hi all,

I’m still relatively new to Godot and I have a problem.
I’m trying to set up a scene change through a node called “portal”.
Basically the idea is to start a FadeOut( or blackout) animation, wait until the animation is done, change the scene, and then begin Fading In.
However, the problem that I’m facing is that FadeOut, yield and change_scene work, but the FadeIn animation doesn’t.
what could the problem be?

tool

extends Area2D

export (String, FILE) var next_path = ""

func _on_Portal_body_entered(body):
	$AnimationPlayer.play("FadeOut")
	yield($AnimationPlayer, "animation_finished")
	get_tree().change_scene(next_path)
	$AnimationPlayer.play("FadeIn")
	yield($AnimationPlayer, "animation_finished")
:bust_in_silhouette: Reply From: Asthmar

This is probably because you are changing the scene so the rest of the code cannot run.

You can use an Autoload. So put your fading_in and scene changer into a global script.
Autoload Doc page: Singletons (Autoload) — Godot Engine (stable) documentation in English

If you don’t know how to use Autoloads yet then just put the fade-in into the scene you are changing to. Try putting it under the ready function so it will be called as soon as the scene is loaded.

Yeah I’m still new to autoloads, and it looks like my assumption of a simple functionality (pause → fade out → wait (yield) for fade out → change scene → fade in → wait for fade in → unpause) is not that simple.

I tried using one autoloaded scene, which combined the change scene and fadeout/in animations, and also tried use two different scenes: one for changing scenes on body enters, the other for fading animations.
So far, no luck.

I’m looking at different tutorials to use a different method for this. I really want to find the simplest way. Because simple things require simple resolutions in the future.

haha-lolcat1 | 2021-07-09 18:02

Yes, I agree, finding a simple way would be best. Not sure if you still haven’t solved the problem but here is how I did fading for an rpg. With just a few lines of code inside an autoload scene.

func fadein():
  $AnimationPlayer.play("fade")

func fadeout():
  $AnimationPlayer.play("fadeout")
  yield(get_tree().create_timer(0.3), "timeout")

 # The method scene is the path to the Scene I want to change to
func SceneChanger(Scene):
 fadein()
 get_tree().change_scene(Scene)
 fadeout()

And the tree is

CanvasLayer
- Animationplayer
- ColorRect

Asthmar | 2021-07-11 06:25

hi Asthmar,

thanks for the help, I figured it out a few days ago, finally!
I had to create a “portal” scene and a “transition” scene-autoload.
it seems that I’ve been missing two key things that resolved my problem:
a yield timer(which you mentioned) and a custom signal within the portal godot code.

Cheers!

haha-lolcat1 | 2021-07-11 14:27

Glad you got it working!

Asthmar | 2021-07-11 17:59