Error calling method from signal 'animation_finished'

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

I try to use Object.connect to run function after an animation is finished playing, but i get an error that said: “'Error calling method from signal ‘animation_finished’: ‘Control(splash_screen.gd)::goto_next_scene’: Method expected 0 arguments, but called with 1”. My code look like these:

splash_screen.gd

extends Control

export (PackedScene) var next_scene

var is_loading = true

func _ready():
	# Enable user input
	set_process_input(true)
	
	# Run animation
	fade_in_out()

# Fade in and out
func fade_in_out():
	$AnimationPlayer.play("fade_in_out")
	$AnimationPlayer.connect("animation_finished", self, "goto_next_scene")

func goto_next_scene():
	# If we are still loading when the splash screen anim is done
	# we try to load next scene every second
	if(is_loading):
		var timer = Timer.new()
		add_child(timer)
		timer.set_wait_time(1)
		timer.set_one_shot(false)
		timer.connect("timeout", self, "next_scene")
		timer.start()
	else:
		next_scene()

func next_scene():
	if(!is_loading):
		print("We are now loadin the next scene from 	the splash screen!")
		
		# Go to the next scene
		get_parent().add_child(next_scene.instance())
		queue_free()

Anyone know what’s wrong with those codes?

:bust_in_silhouette: Reply From: hilfazer

AnimationPlayer’s animation_finished signal has one argument:

Function you connect needs one argument as well (unless signal’s args can be ignored but i’ not aware of this).

Make another function that takes one argument and calls goto_next_scene().

Hi hilfazer, thanks for answering. Could you please give some examples? I have read the Godot 3 docs, but i still don’t understand how to implement it in my game. It said that ‘animation_finished’ signal needed string type argument of the name of some animations. But what animation? Is it the same animation that is currently playing, which in my case fade_in_out anim? Why do i need to make another function to call the signaled method?

rony | 2018-05-09 04:51

It’s a name of animation that has finished playing. In your case it would indeed be fade_in_out.

You’ll need another function to capture an argument that comes with signal. Signal’s signature is this:

animation_finished ( String anim_name )

Try doing something like this:

onFadeInOutFinished( anim_name ):
    goto_next_scene()

And connect it instead of goto_next_scene like this:

$AnimationPlayer.connect("animation_finished", self, "onFadeInOutFinished")

You don’t want to add and argument to goto_next_scene() because it has no business knowing it’s being called because some animation has stopped playing.

hilfazer | 2018-05-09 05:28

Thanks again, it works. But what’s with Godot 3 and unused arguments anyway? I learn godot from tutorial based on godot 2, most of the errors i got, beside some name differences of classes and methods , are from the missing arguments.

rony | 2018-05-09 07:29

Apparently signal’s arguments have to be captured by connected function. I wish Godot could ignore extra signal arguments just like the father of signals & slots concept, Qt Framework, does. Maybe a future version will be doing this.

hilfazer | 2018-05-10 16:13