+1 vote

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 'animationfinished': 'Control(splashscreen.gd)::gotonextscene': 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?

asked May 8, 2018 in Engine by _rony_ (13 points)

1 Answer

+2 votes

AnimationPlayer's animation_finished signal has one argument:
http://docs.godotengine.org/en/3.0/classes/class_animationplayer.html?highlight=animation_finished#signals
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().

answered May 8, 2018 by hilfazer (2,112 points)

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 fadeinout anim? Why do i need to make another function to call the signaled method?

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.

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.

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.

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 How to use this Q&A? before posting your first questions.