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


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.new()
        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?

in Engine by (13 points)

1 Answer

+2 votes

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().

by (2,298 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 ):

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 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.