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
相关产品推荐
相关产品推荐

