Hey All!

My character has a magic notebook that appears to give him hints. I've created custom signals from my dialog script to tell the notebook sprite when to appear. After the notebook's "appear" animation, I want it to play it's "float" (idle) animation, so I used the animated sprite's animation_finished signal to trigger the "float" animation. That's all good and well! But when the dialog ends, I want the notebook to play the "disappear" animation. My problem is the "animation_finished" signal keeps firing, so the "float" animation keeps playing. I thought disconnecting the signal before running the "disappear" animation would work, but nothing happens. I'd appreciate any thoughts on how I might fix this OR how I might do this better!

Thanks y'all! 🙂

Here's the code in question:

func _on_DialogBox_dialog_start():
	$Notebook.visible = true
	$Notebook.play("appear")

func _on_DialogBox_dialog_end():
	$Notebook.disconnect("animation_finished", self, "_on_Notebook_animation_finished")
	$Notebook.play("disappear")
	

func _on_Notebook_animation_finished():
	$Notebook.play("float")

You're missing the underscore character in front of function name passed to disconnect()

I'm sorry, I'm not sure I understand. Are you suggesting this code?

func _on_DialogBox_dialog_end():
	$Notebook.disconnect("_animation_finished", self, "_on_Notebook_animation_finished")
	$Notebook.play("disappear")

Adding the _ before "animation_finished" didn't seem to work.

In the original post, the underscore at the beginning of the third parameter was missing, but I guess you fixed that.

Is this Godot 3.5.x?

Do you get any error messages? The animation_finished signal passes a parameter anim_name. Try including that and printing its value.
https://docs.godotengine.org/en/3.5/classes/class_animationplayer.html?#signals

func _on_Notebook_animation_finished(anim_name: String) -> void:
        print_debug("anim_name=", anim_name)
	$Notebook.play("float")

    DaveTheCoder

    Hey Dave! I'm using Godot 3.4.4 stable - should I update?

    I'm also not seeing where I neglected to add an underscore. The third parameter being "_on_Notebook_animation_finished"? I believe the underscore is there in the first post?

    I'm still very much learning, so I appreciate the help!

    The code in the first post looks correct now.
    You should upgrade to 3.5.2-stable, although that might not affect this issue. But make a backup first.

      If you don't provide the right number of parameters with a function signal, it silently doesn't get called.

        DaveTheCoder

        Hey Dave! I tried the code you provided above to print the anim_name. It ended up not printing anything in the Godot's output - it also stopped the function from working (didn't play the "float" animation). Is that because we included void?

        Was the function working before? If you remove the anim_name parameter but leave in a print_statement, does it print?
        print_debug("_on_Notebook_animation_finished")

        The -> void doesn't matter. You can remove it. It's part of static typing, which I personally prefer because it makes the code more reliable, but it's not essential.

        You didn't say whether you get any error messages. The screenshot in your post below says there are 15 warning or error messages. What are they?

        Maybe a screenshot of my node setup would be helpful! Is there a reason my disconnect function wouldn't reach my notebook node? I've also tried $Notebook.disconnect(...) to no avail.