How to call method from AnimationPlayer that pauses and resumes animation without the method being called multiple times?

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

I have an AnimationPlayer which starts a cutscene animation. At 1 second, the AnimationPlayer calls the method PlayDialog() on my custom CutscenePlayer.cs class, which calls animationPlayer.Pause() and then handles some dialog being shown to the player. Once the dialog is finished, a callback is called which calls animationPlayer.Play(“”) again.

However, instead of advancing through the rest of the animation track as expected once the dialog is finished, PlayDialog() gets called again just after animationPlayer.Play(“”) is called, and you can click through again but every time you finish the dialog it just starts playing again. How can I fix this?

I assumed that pausing and unpausing right when the method was fired from the AnimationPlayer was causing the PlayDialog() call to fire twice, but even if I animationPlayer.Advance(1.0f) to advance a second before unpausing, I still have the same problem. Does anyone have any ideas?

It may be a bug, please open an issue here Issues · godotengine/godot · GitHub explaining what you want to do and what’s the issue you are facing.

As a workaround you can set the AnimationMixer.callback_mode_process property to AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL and AnimationMixer.advance() the animation manually like:

extends Node

@onready var animation_player: AnimationPlayer = $AnimationPlayer

var paused = false


func _ready() -> void:
	animation_player.callback_mode_process = AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL
	animation_player.play('new_animation')


func pause_anim() -> void:
	printt('pausing', animation_player.current_animation_position)
	paused = true


func _process(delta: float) -> void:
	if not paused:
		animation_player.advance(delta)
	if Input.is_action_just_pressed("ui_accept"):
		print('playing')
		paused = false

The issue seems to be fixed in latest master probably by Fix wrong line of making flag to discrete in AnimationMixer by TokageItLab · Pull Request #89329 · godotengine/godot · GitHub