0 votes

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 emitsignal: 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?

Godot version 3.5
in Engine by (99 points)

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

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

1 Answer

0 votes

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
by (570 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.