Search code examples
godotgdscript

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


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?


Solution

  • The variables you bind are passed in addition to the ones that the signal passes… And animation_finished passes the name of the animation. So the method you are calling (set) would actually get three arguments. To deal with that make and extra method - which ignores the first parameter - and connect to it instead.