Search code examples
godotgdscript

Set animation position


I'm using Godot 4 beta. I want to skip to a specific frame in an AnimationPlayer, but I'm getting:

Invalid set index 'current_animation_position' (on base: 'AnimationPlayer') with value of type 'float'.

Here's the related documentation: https://docs.godotengine.org/en/latest/classes/class_animationplayer.html#class-animationplayer-property-current-animation-position

I currently have one AnimationPlayer in my scene, named 'animation', with an animation named 'Animation' with "Autoplay on Load". The animation 'Animation' has a length of 4.x seconds.

Editor (1)

Here's my code attached to the scene:

func _process(_delta):
    if Input.is_action_just_released("skip_intro"):
        if animation_player.current_animation_position < 1.3:
            animation_player.current_animation_position = 1.3
        else:
            skip_intro()

Update (2)

I know I can use animation_player.advance(), but it adds to the relative time. I'm looking for a way to go to a fixed frame, not a relative frame.


Solution

  • As you can read in the documentation you linked current_animation_position only has a getter. It is a read-only property.

    If you want to go to an specific time you can use the seek method.