Skip to content

Instantly share code, notes, and snippets.

@WolfgangSenff
Created December 5, 2023 15:33
Show Gist options
  • Save WolfgangSenff/d7e192734c2c5675002b0708523b18ff to your computer and use it in GitHub Desktop.
Save WolfgangSenff/d7e192734c2c5675002b0708523b18ff to your computer and use it in GitHub Desktop.
Binding arguments in GDScript
func _ready() -> void:
$AnimationPlayer.animation_finished.connect(_on_animation_finished.bind(func(): $StateMachine.change_to($StateMachine/JumpState)))
# Above will add an extra argument to the function when animation_finished is emitted that's equal to the Callable in this case.
# The callable is used below. Note the change in signature to the function for the signal.
func _on_animation_finished(anim: String, on_complete: Callable) -> void:
on_complete.call() # This ensures that the func() we passed in on line 2 is executed only after an animation is finished.
# You might want this if, for example, you have a longer "start" to an animation, but the part which repeats is
# a separate animation. I use this for when a special attack has a "wind-up", but the wind-up isn't part of
# the repeated animation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment