如题, 将MeshRenderer隐藏, 调用SetAnimation切换动画后再打开MeshRenderer,Spine动画会显示异常,目前有两种方式可以规避
1: MeshRenderer设置为Enable后,重置动画,清理轨道信息,再设置动画并且将动画设置为对应的time
2:修改SkeletonAnimation的scale为0,MeshRenderer设置为Enable后再设置为1
但是第一种方式会担心性能问题,第二种方式会导致MeshRenderer关闭期间,动画暂停.
请问是否有其它的方式能解决这个问题?
隐藏MeshRenderer切换动画,再打开MeshRenderer会导致显示异常
@July Disabling and re-enabling the MeshRenderer
of a SkeletonAnimation
GameObject does not cause any issues. Which exact version of the spine-unity runtime (name of the unitypackage, also listed in Assets/Spine/version.txt
, or the Package Manager) are you using?
What are you trying to achieve in the first place, what problem do you want to solve by disabling the MeshRenderer? If you want to hide the whole skeleton, it would likely be more reasonable to disable the whole GameObject, as otherwise SkeletonAnimation
would still be updating animations and generating the mesh, wasting CPU cycles.
- Modifié
I want the Spine character to be hidden when it moves out of the camera's view, while keeping the animation logic running. When it re-enters the camera's view, the animation should display at the correct time. To achieve this, I set the Spine component's Update When Invisible to OnlyAnimationStatus, and disable the MeshRenderer when it's out of view, then re-enable it when it comes back. However, if the animation is changed while the Renderer is disabled outside the camera view, enabling the Renderer again when the character reappears causes animation display issues.
July However, if the animation is changed while the Renderer is disabled outside the camera view, enabling the Renderer again when the character reappears causes animation display issues.
Thanks for the clarification. What display issues do you encounter, do you perhaps see an old animation state for a frame? Depending on from where you call your code (e.g. from Update()
), you may be too late after SkeletonAnimation.Update
has already been called this frame (see the documentation on Script Execution Order) and have to call skeletonAnimation.Update(0)
manually after setting your animations.
Thanks for your reply!
The issue I'm encountering is that the current animation displays incorrectly — it appears to be mixed with images or motions from other Spine animations, as if multiple animation states are blended together.
I tried calling skeletonAnimation.Update(0) immediately after setting the animation, but the issue still persists, so it might not be related to the script execution order.
Currently, the only way I can make the display work correctly is:
After re-enabling the MeshRenderer, I cache the current animation name, trackTime, and loop status;
Call ClearTracks() to clear existing animations;
Use SetAnimation() to reassign the cached animation;
Manually set newEntry.TrackTime = cached time.
This workaround solves the problem, but it feels a bit cumbersome, and I'm not sure if it's the recommended approach. I'd really appreciate any further suggestions!
July The issue I'm encountering is that the current animation displays incorrectly — it appears to be mixed with images or motions from other Spine animations, as if multiple animation states are blended together.
I can't imagine how such a situation could occur. In general there should be no workarounds necessary. Unfortunately we can't help with the provided information alone. Could you share a minimal Unity project which still shows this issue? You can send it as a zip file to contact@esotericsoftware.com, briefly mentioning this forum thread URL so that we know the context. Then we can have a look at what's going wrong.
@July Thanks for sending the reproduction project. It seems that there are leftover slots being enabled which should not be. Unfortunately I don't yet know why disabling and re-enabling the MeshRenderer
causes this issue to arise and why it does not occur otherwise. This is a bit puzzling. What does resolve the issue though is calling skeletonAnimation.Skeleton.SetSlotsToSetupPose()
before calling AnimationState.SetAnimation
. This should be a better workaround than your originally discovered one.
I've created in issue ticket here where you can subscribe to receive notifications upon any updates:
EsotericSoftware/spine-runtimes2873
Thanks for reporting and sorry for the troubles!