• RuntimesUnity
  • 游戏运行中,是否可以切换SkeletonDataAsset

@fengmin Sorry to the inconvenience, thanks for reporting! There was indeed no way to properly update the referenced bones and AnimationState references in SkeletonRootMotion after changing SkeletonDataAsset and calling skeletonAnimation.Initialize(true).

We have just pushed a commit which now automatically updates all references at SkeletonRootMotion automatically.

A new spine-unity 4.2 unitypackage is available for download here as usual:
https://esotericsoftware.com/spine-unity-download

From the changelog:

SkeletonRootMotion components now provide a public Initialize() method which is automatically called when calling skeletonAnimation.Initialize(true) to update the necessary skeleton references. If a different root bone shall be used, be sure to set skeletonRootMotion.rootMotionBoneName before calling skeletonAnimation.Initialize(true).

Issue ticket URL for later reference:
EsotericSoftware/spine-runtimes2575

  • fengmin đã trả lời bài viết này.
  • fengmin đã thích điều này.
    Related Discussions
    ...

    Harald 感谢,SkeletonRootMotion组件现在可以正常工作了,但是正如spinebot所说其他依赖于 animator 的对象也失效了,例如我自定义的动画控制脚本中的animator,我该如何编写类似SkeletonRootMotion的新Initialize函数,以及在什么时候调用来使我的脚本和SkeletonRootMotion一样继续正常工作。
    顺便我还发现一件事,
    当我使用脚本animator.Initialize(true);时,其他依赖于 animator 的对象以及为animator 设置的事件监听失效了
    但是如果我使用SkeletonAnimation在inspector窗口中的Reload按钮,则不会失效
    我能否有办法在脚本中使用Reload按钮,而不是Initialize函数

    @fengmin You can register your own components to the skeletonAnimation.OnAnimationRebuild callback to get notified when Initialize(true) invalidates e.g. your skeleton and AnimationState.

    skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild;
    ..
    
    protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) {
    	Initialize();
    }

    You can find the same code in SkeletonRootMotionBase.cs:
    EsotericSoftware/spine-runtimesblob/4.2/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs#L179

    在使用SkeletonRootMotion我发现骨骼会在动画最后一帧时,回到动画的初始位置,同时使用BoneFollower 的时候,就会出现Follow的物品跟着闪烁一下,有什么办法解决吗

    When using SkeletonRootMotion, I found that the skeleton will return to the initial position of the animation at the last frame of the animation.

    Could you please describe that in more detail, when exactly does that happen? If it happens all the time, then root motion is not active (for whatever reasons not doing anything). Or does it revert to the initial position only once after changing your SkeletonDataAsset?

    When using BoneFollower at the same time, the Follow items will flash. Is there any solution?

    Could you please describe what exactly happens? It has been translated as "flash", do you mean the BoneFollower object's position is wrong for a single frame?

    • fengmin đã trả lời bài viết này.

      Harald 抱歉,我得更正一点,不是使用BoneFollower时,是使用SkeletonUtility的Follow All Bones的时候
      当动画循环播放时,例如跑步动画,会在动画的最后一帧到第一帧的时候,骨架会回到原位一帧的时间
      设置如下


      或者会不会是我的动画本身有问题,我在动画中移动的是RoleRoot节点的坐标并且将其作为了其他节点的父对象

      • fengmin đã trả lời bài viết này.

        @fengmin Thanks for the additional info. Is your run animation three cycles long in a single animation? The issue seems to occurs only after the third cycle.

        How is the GameObject transform position moving? Unfortunately the video shows the RectTransform tool active, with no RectTransform borders visible either. Could you please share a video where the Translate tool is active, so that we can see the GameObject origin moving?

        • fengmin đã trả lời bài viết này.

          Harald
          视频中的动画循环了3次,该问题是每次都触发,只是由于视频帧数您只能在我暂停的第三次看见该现象

          fengmin 或者会不会是我的动画本身有问题,我在动画中移动的是RoleRoot节点的坐标并且将其作为了其他节点的父对象

          GameObject本身的位移是没有发生回溯的,只有骨骼发生了回溯,抱歉不知道为什么录屏的鼠标位置有向上偏移,请留意鼠标下方和实际选中的对象

          @fengmin Thanks for the additional information and videos. This indeed looks strange, we have not yet encountered such an issue. Could you please send us a minimal Unity project which still shows this issue? You can send it as a zip package 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.

          • fengmin đã trả lời bài viết này.

            Harald 压缩包已经发送到邮箱了,辛苦您了
            另外,我还是对游戏运行中切换SkeletonDataAsset的实现方法没有头绪
            目前我发现使用Reload按钮是最完美切换方式,但是我不知道如何在代码中调用该按钮或者编写和Reload按钮功能相似的方法

            • Harald đã trả lời bài viết này.

              fengmin Harald 压缩包已经发送到邮箱了,辛苦您了

              Thanks for sending the reproduction project. We received everything. Please note that you should not add the project to Unity Version Control when sending it as a reproduction project. I had to manually remove the Unity Collaboration package to fix any errors. Nevertheless, I could now reproduce your issue. We will get back to you here on the forum once we know what's going wrong.

              fengmin 目前我发现使用Reload按钮是最完美切换方式,但是我不知道如何在代码中调用该按钮或者编写和Reload按钮功能相似的方法

              Please check out this recent forum posting here:
              https://esotericsoftware.com/forum/d/26544-reload-skeletondataasset-in-runtime/2
              Or this one for SkeletonGraphic (which also shows setting initialSkinName and startingAnimation)https://esotericsoftware.com/forum/d/26432-skeletondataasset-swap-in-runtime-has-blue-tint/2

              @fengmin We have just released a bugfix for SkeletonUtilityBone updating too late (before SkeletonRootMotion moves the bone back).

              A new spine-unity 4.2 unitypackage is available for download here as usual:
              https://esotericsoftware.com/spine-unity-download
              Please let us know whether this fixes the issue on your end as well. Thanks for reporting.

              Issue ticket URL for later reference:
              EsotericSoftware/spine-runtimes2582

              • fengmin đã trả lời bài viết này.
              • fengmin đã thích điều này.

                Harald
                非常感谢,问题成功得到了解决

                @fengmin Glad to hear, thanks for getting back to us.