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(’: Method expected 0 arguments, but called with 1”. My code look like these:

extends Control

export (PackedScene) var next_scene

var is_loading = true

func _ready():
	# Enable user input
	# Run animation

# Fade in and out
func 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
		var timer =
		timer.connect("timeout", self, "next_scene")

func next_scene():
		print("We are now loadin the next scene from 	the splash screen!")
		# Go to the next scene

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

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