Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spine隐藏时调用setAnimation报错 #17038

Closed
kaxifakl opened this issue May 23, 2024 · 11 comments
Closed

spine隐藏时调用setAnimation报错 #17038

kaxifakl opened this issue May 23, 2024 · 11 comments
Assignees
Labels
Milestone

Comments

@kaxifakl
Copy link
Contributor

Cocos Creator version

3.8.3

System information

Window 10

Issue description

1.节点一开始active=false,调用setAnimation播放动画,此时会报错

    protected onLoad(): void {
        this.skeleton.setAnimation(0, 'run', true);
        this.skeleton.node.active = true;

        console.log(this.skeleton)
    }

image
2.手动调用skeleton初始化,此时不会报错,但动画不会播放

    protected onLoad(): void {
        if (!this.skeleton._skeleton) {
            this.skeleton.__preload()
        }
        this.skeleton.setAnimation(0, 'run', true);
        this.skeleton.node.active = true;

        console.log(this.skeleton)
    }

Relevant error log output

No response

Steps to reproduce

打开上传的项目,运行scene场景

Minimal reproduction project

NewProject_383.zip

@kaxifakl kaxifakl added Bug Needs Triage Needs to be assigned by the team labels May 23, 2024
@bofeng-song
Copy link
Contributor

@kaxifakl setAnimation先改成 在node.active=true后面,这个问题后面会修复

@kaxifakl
Copy link
Contributor Author

哪个版本会修复?

@kaxifakl
Copy link
Contributor Author

@bofeng-song 这个问题还有后续吗

@bofeng-song
Copy link
Contributor

385处理

@kaxifakl
Copy link
Contributor Author

@bofeng-song 这个操作只是不让它报错,在未激活前setAnimation还是无效的。是否有一些缓存机制让animationName缓存下来呢?

@bofeng-song
Copy link
Contributor

@bofeng-song 这个操作只是不让它报错,在未激活前setAnimation还是无效的。是否有一些缓存机制让animationName缓存下来呢?

image
active后,会设置skeletonData,这个时候需要重新设置animationName,不然animation可能是不存在的。

@kaxifakl
Copy link
Contributor Author

@bofeng-song 那这时候是否可以直接用缓存的animationName赋值呢,并且验证一下animationName是否有效

@minggo minggo added this to the 3.8.5 milestone Oct 30, 2024
@minggo minggo removed the Needs Triage Needs to be assigned by the team label Oct 30, 2024
@bofeng-song
Copy link
Contributor

@kaxifakl setSkeletonData 接口正常只做和skeletonData有关的事情,不应该顺带执行setAnimation,这样会职责不清晰

@kaxifakl
Copy link
Contributor Author

kaxifakl commented Oct 30, 2024

@bofeng-song 这里的问题应该是,skeleton组件未激活前,手动赋值了SkeletonData,但__preload()方法未执行,所以this._skeleton为空,此时setAnimation, 会在这里被return
image

@kaxifakl
Copy link
Contributor Author

@bofeng-song https://github.com/cocos/cocos-engine/issues/17784 这个issue也是同样的问题,SkeletonData赋值后,setAnimation应该设计为可以被成功调用,即使节点未被激活

@bofeng-song
Copy link
Contributor

@kaxifakl
https://github.com/cocos/cocos-engine/issues/17784
这个的根本问题是节点重用,skeleton因为skeletonData设置null而被置空,第二次使用时,未对skeleton进行赋值

@minggo minggo closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants