• Unity
  • May I ask how SkeletonGraphic gets a skeleton world position

Related Discussions
...

Hello, I have a need to get the position of a character's hand. This character is a circular animation, and the position I get now is a fixed value.

     
using System.Collections; using System.Collections.Generic; using Spine; using Spine.Unity; using UnityEngine; public class test : MonoBehaviour { public SkeletonGraphic skeletonGraphic; private BoneData bons; private Bone bons2; public SkeletonRenderer skeletonRenderer; void Start() { skeletonGraphic = this.transform.GetComponent<SkeletonGraphic>(); // bons2 = skeletonRenderer.skeleton.FindBone("body_02"); // bons2.UpdateWorldTransform(); var exposedList = skeletonGraphic.skeletonDataAsset.GetSkeletonData(true).Bones; foreach (var VARIABLE in exposedList) { if (VARIABLE.name == "body_02") { bons = VARIABLE; // print(VARIABLE.parent); // print(VARIABLE.X); // print(VARIABLE.Y); // print(VARIABLE.Rotation); } } } // Update is called once per frame void Update() { // bons2 = skeletonRenderer.skeleton.FindBone("body_02"); // bons2.UpdateWorldTransform(); // bons2.GetWorldPosition(skeletonRenderer.transform); print(bons.X); print(bons.Y); print(bons.Rotation); } }

The location of the printing remains unchanged. How can I get the change? Thank you.

try add

skeletonGraphic.skeleton.UpdateWorldTransform();

in your Update()

There may be a difference between calling on a bone and the skeleton.

I have posted a reply on this other thread here:
请问下SkeletonGraphic怎么获取到某个骨骼的世界位置啊

Nick escribió

try add

skeletonGraphic.skeleton.UpdateWorldTransform();

in your Update()

There may be a difference between calling on a bone and the skeleton.

Thanks for helping out @Nick, always appreciated!
This code above will unfortunately not help since the problem lies with accessing SkeletonData instead of the instance Skeleton bone state.

Apart from that, it's recommended to use the UpdateWorld delegate when reading or writing bone locations instead of querying the position in Update, as explained here:
spine-unity Runtime Documentation: Getting and Setting Bone Transforms Manually