Fade effect not working during timer

Godot Version

4.3

Question

i have this code

func _on_outro_timer_timeout() -> void:
	if Globals.rested_2_completed:
		$"../outro_timer".start()
		fade_effect_animation.play("fade_to_black")
		get_tree().change_scene_to_file("res://Scene/outro.tscn")

once the bool is true, timer starts for 10 seconds and then it move to next scene, this works fine, but I want fade animation to work, and it doesn’t. why is that? i want fade animation to work while timer is working.

  1. the outro_timer is started, Godot does not wait for it to finish
  2. the fade_effect_animation starts to play, Godot does not wait for it to finish
  3. the scene is changed, everything is destroyed

For a script to wait for a timer or animation to play you must use the await keyword on a signal or blocking function.

func _on_outro_timer_timeout() -> void:
	if Globals.rested_2_completed:
		$"../outro_timer".start()
		fade_effect_animation.play("fade_to_black")

		await fade_effect_animation.animation_finished

		get_tree().change_scene_to_file("res://Scene/outro.tscn")

If all you are doing is fading to black there is likely no reason to use the animation player.
Switch to a tween and you can change scenes on the tween complete signal.
This way you can turf both the timer and the animation player for this simple effect.

ok i see what you mean, i will give it a try

well i have fade to_normal in ready func when scene starts, and fade_to_black when this timer is over and moving to next scene, so can it work for both? il give it a try and look online

You can use my way… I think it is better:

1- Make a global script for the animations.
2- Make your animation as a CanvasLayer in a seperate scene.
3- Instantiate the scene in _ready() function in the Global script and add it to the root node (get_tree().root), do not add it to the current scene.
4- make functions in the global script for the fade in and fade out, or make a singe fuction for changing the scene which plays the fade in animation, changes the scene, plays the fade out.

seems to complicated and longer to do, i dont require much, I solved my issue anyway, I used the await the other guy gave me

Right… I use this way to play some complicated transition between scenes such as a door close then open.