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

Ursina引擎销毁Animator对象报eternal属性不存在错误如何解决

Ursina中Animator对象销毁报错的解决方法

报错原因

Ursina 内置的 destroy() 函数默认仅支持销毁继承自 Entity 类的实例。Animator 属于独立的动画控制类,没有继承 Entity 的相关属性,因此直接调用 destroy(animator1) 会触发 AttributeError: 'Animator' object has no attribute 'eternal' 报错。

正确销毁步骤

  • 优先销毁 Animator 关联的所有动画实例,避免内存中残留无效资源
  • 清空 Animator 内部的动画字典绑定
  • 解除 Animator 的状态绑定
  • 最后删除变量引用,触发 Python 垃圾回收完成销毁

修正后的代码示例

from ursina import *
app = Ursina()
walka = Animation("assets/zombies/zombie1/walk/", fps=5, loop=True)
animator1 = Animator(animations={"walk": walka})
animator1.state = "walk"

# 正确销毁Animator逻辑
# 销毁关联的动画实体
destroy(walka)
# 清空动画字典,解除资源绑定
animator1.animations.clear()
# 重置状态解除状态绑定
animator1.state = None
# 删除变量引用,触发垃圾回收
del animator1

app.run()

注意:不推荐通过手动给 Animator 实例添加 eternal = False 属性的方式绕开报错,该方式仅能避免报错,无法真正释放 Animator 关联的动画资源,会造成内存冗余。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 02:39:05