0 votes

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?


extends Area2D

export (String, FILE) var next_path = ""

func _on_Portal_body_entered(body):
    yield($AnimationPlayer, "animation_finished")
    yield($AnimationPlayer, "animation_finished")
Godot version v3.3.2.stable.official
in Engine by (95 points)

1 Answer

+1 vote
Best answer

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: https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html

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.

by (709 points)
selected by

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.

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():

func 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):

And the tree is

- Animationplayer
- ColorRect

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.


Glad you got it working!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.