Error calling method from signal 'animation_finished': 'set': Method expected 2 arguments, but called with 3

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

I’m trying to reset the value of a variable after the animation is complete like this:

extends Node2D

var testing=false

func _ready():
	var ani_player=$AnimationPlayer
	ani_player.play("ani_2")
	ani_player.connect("animation_finished",self,"set",["testing",false])

but for some reason it gives the error:

E 0:00:00.479 emit_signal: Error calling method from signal
‘animation_finished’: ‘Node2D(Main.gd)::set’: Method expected 2
arguments, but called with 3… <C++ Source> core/object.cpp:1242 @
emit_signal()

which makes no sense I’m passing 2 variables ["testing",false] why does it keeping getting a third one?
am I missing something?

it is not connection, check out your receiving function. You had it expect 2 arguments like

func set(x,y)

but something calls more upon emitting. Propably it calls private arguments AND additional ones You introduced in connection

Inces | 2022-12-15 21:04

The animation_finished Signal has its own argument that also gets passed along hence the 3 arguments
Additionally its argument always gets passed along first

Wakatta | 2022-12-16 01:41

:bust_in_silhouette: Reply From: godot_dev_

You define your signal handler function set to be called when the animation_finished signal is emitted. According to the documentation of AnimationPlayer, the animation_finished signal has an argument, the name of the animation that finished playing. When you connected your set function , you also added 2 additional parameters that will be passed to set. The error of expected 2 arguments but called with 3 is likely because your set function is defined to only have 2 arguments.

Solution: Define your set function with a 3rd argument as follows:

func set(anime_finished_name,strArg,boolArg): 
    pass