• International中文
  • SkeletonUtility脚本生成的骨骼,部分骨骼节点位置异常

下图红框中的骨骼,应该出现在箭头位置,这个骨骼是由SkeletonUtility脚本生成的

应该和下图Spine编辑器中位置对应

该骨骼应用了变换约束,但是该角色的其他骨骼看起来是正常的

我使用的是Unity2022.3.17f1c1, Spine-unity4.1

Related Discussions
...

这个骨骼在另一个角色的皮肤中是正确的,该角色也同样应用了变换约束。这个位置异常的骨骼在挂载BoneFollower脚本之后位置就变得正常了,这是我这边补充的线索。

不知道这个问题是什么原因引起的,希望能得到你们的帮助,谢谢

@ECG_Kinsey What does your SkeletonUtilityBone hierarchy look like?

Please note that SkeletonUtilityBone uses local transform values. It relies on a hierarchy of SkeletonUtilityBone GameObjects that mirrors the skeleton's bone hierarchy.
See the documentation here:
https://esotericsoftware.com/spine-unity#SkeletonUtilityBone

@ECG_Kinsey Also, which exact versionof the spine-unity runtime (name of the unitypackage, also listed in Assets/Spine/version.txt or version in the Unity Package Manager) are you using?

    Harald 层次结构如下

    该层次结构由SkeletonUtility脚本的"SpawnHierarchy"按钮生成,生成之后并无改动。

    Spine-Unity运行时版本为spine-unity-4.1-2024-03-19.unitypackage

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

      ECG_Kinsey 该层次结构由SkeletonUtility脚本的"SpawnHierarchy"按钮生成,生成之后并无改动。

      Thanks for the additional info.

      Could it be that some of the parent bones use any special transformations, like not inheriting position or scale or the like? Such transformation would be lost when trying to re-create it in Unity since a Unity Transform can't disable inheritance.

        Harald 我的Spine骨骼中确实有一些不继承缩放的变换,这是因为我需要通过缩放骨骼来使不同骨架比例的角色复用同一套动画,而部分骨骼缩放之后,其骨骼所对应的附件尺寸也会缩放,所以我勾选了不继承缩放来保持附件的尺寸不变。

        以及还有一个现象,骨骼动画的模拟unity和Spine中是一致的,并且异常位置的骨骼在挂载BoneFollower脚本之后位置可以得到正确的修正,所以我认为这意味着Spine可以在Unity中获取正确的骨骼的位置,这也是骨骼动画能正确模拟并且异常骨骼在挂载BoneFollower之后能恢复正常的原因,因为Spine拥有该骨骼正确的位置数据,可能是SkeletonUtility脚本生成骨骼的逻辑有一定bug?

        Harald 这个骨骼在unity中模拟动画的时候位置信息是正确的,如下图

        而在SkeletonUtility生成骨骼后,下图中的SkeletonUtility提供的骨骼信息里,这个点的位置就是不对的

        这两个信息为什么不统一,问题是否可能出现在这个地方?

        @ECG_Kinsey As I said before, if you are using some features in the skeleton like disabled Inherit Scale, these can't be mirrored by Unity Transform. If you use a SkeletonUtilityBone hierarchy, which uses Unity Transform to position itself, when the bone or any of the parent bones in the hierarchy has Inherit Scale disabled, you will end up with incorrect bone location.

        Please check or even better share screenshots of the settings of all parent bones of the problematic bone in the Spine project, whether they have e.g. Inherit Scale or similar disabled.

          @ECG_Kinsey In other words, you can do this in Spine:

          - parent [scale 3] world scale = 3
          -- child [scale 1, disabled inherit scale] world scale = 1

          But in Unity this can only become

          - parent [scale 3] world scale = 3
          -- child [scale 1 [ no disabled inherit scale support ] world scale = 3 (!!)

          Harald 是的,我明确我项目中有禁用缩放的骨骼节点。这是因为我们通过皮肤制作不同的角色,不同角色之间共用一个骨架,但是他们有不同的身体比例,为了复用同一套动画,我们通过变换约束缩放了部分角色皮肤下的骨骼,缩放后的骨骼会影响附件中的图片的比例,为了保持图片的比例不受影响,我们禁用了继承缩放。

          我理解了你说的Spine和unity对变换的缩放继承的逻辑不同。但是我仍然有一个疑问,下面两个图都是来自Unity,而骨骼信息都来自Spine,既然unity和Spine对变换的缩放继承处理逻辑不同,如果一个存在禁用缩放继承的Spine工程导入unity之后,按理来说应该无法在unity还原Spine中的变换,为什么第一个图箭头所指的骨骼能在正确的位置?

          我们有需求需要获取这个点的坐标信息,我需要做什么才能拿到这个数据?
          希望能再次得到您的指导,谢谢

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

            We need to obtain the coordinate information of this point.

            You can use Bone localToWorld, eg:

            float worldX, worldY;
            bone.LocalToWorld(0, 0, worldX, worldY);

            This gives you the coordinate in the skeleton's world space (relative to the skeleton's position). You can then convert this to a GameObject's space if needed.

            Thanks for confirming that you're using disabled Inherit Scale.
            The easy solutions would then be:

            • If you need to only let a Transform follow a bone position, please always use the BoneFollower component, as it has less overhead and fewer issues than the complete SkeletonUtilityBone hierarchy.
            • If you need to override the bone position of e.g. an arrow bone, you can use the SkeletonUtilityBone component with Mode Override only for the arrow bone without the complete parent hierarchy. Then for the required parent have just a single BoneFollower GameObject which is set to follow the parent bone of the arrow bone. Then at the arrow SkeletonUtilityBone you can set the Parent Reference to the BoneFollower game object.

            ECG_Kinsey 但是我仍然有一个疑问,下面两个图都是来自Unity,而骨骼信息都来自Spine,既然unity和Spine对变换的缩放继承处理逻辑不同,如果一个存在禁用缩放继承的Spine工程导入unity之后,按理来说应该无法在unity还原Spine中的变换,为什么第一个图箭头所指的骨骼能在正确的位置?

            The bone position in the first screenshot is in the correct position because we calculate world positions without using any Unity components for that. We don't have a Unity Transform hierarchy behind the skeleton bones.

              Harald 明白了,感谢您的耐心解答,这很有帮助

              • Harald đã thích điều này.

              Glad it helped, thanks for getting back to us.