You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot 4 Beta中AnimationPlayer设置指定帧报错求助

Godot 4 Beta:AnimationPlayer跳转到固定时间点的报错修复

报错原因

你碰到的Invalid set index 'current_animation_position' (on base: 'AnimationPlayer') with value of type 'float'错误,核心原因是Godot 4里current_animation_position是只读属性,不能直接赋值修改。

正确实现方式

要跳转到动画的固定时间点,别用赋值的方式,改用AnimationPlayer的seek()方法——这个方法接受绝对时间参数,正好满足你跳转到固定位置的需求,和相对累加的advance()完全不同。

修改后的代码:

func _process(_delta):
    if Input.is_action_just_released("skip_intro"):
        if animation_player.current_animation_position < 1.3:
            # 跳转到1.3秒的位置,第二个参数设为true表示跳转后继续播放(按需改成false可暂停)
            animation_player.seek(1.3, true)
        else:
            skip_intro()

注意事项

  • 确保代码里的animation_player和场景中名为animation的AnimationPlayer节点引用一致,避免出现节点未找到的隐性问题。
  • seek()的第二个参数keep_playing默认是true,如果需要跳转后暂停动画,把参数改成false即可。

内容的提问来源于stack exchange,提问作者Hydroper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 07:10:27