• Editor
  • Ui spine with Attachment

hello everyone. I have a spine animation and in this animation there is a Attachment that should change its position depending on the animation. I found this Attachment, but the problem is that in the UI space, the change of this Attachment is the same as in the usual space, although the animation itself moves perfectly in the UI space. how do I translate the coordinates of this point in UI space?

How i get position:
var bone = targetSlot.Bone;

    Vector2 worldPosition = targetAttachment.GetWorldPosition(bone, skeletonGraphic.transform);

    Vector3 canvasPosition =
        skeletonGraphic.transform.TransformPoint(new Vector3(worldPosition.x, worldPosition.y, 0f));

whats wrong?

Related Discussions
...

@vampodav Spinebot's code unfortunately was incomplete in regards to ignoring mesh scale and offset due to SkeletonGraphic's Layout Scale, and also likely ignoring Canvas scale. I've removed the posting as it might be a bit misleading.

For SkeletonGraphic the extension method Bone.GetWorldPosition() with additional scale and offset parameters must be used (see the method here):

float positionScale = skeletonGraphicComponent.MeshScale;
Vector2 positionOffset = skeletonGraphicComponent.GetScaledPivotOffset();

bone.GetWorldPosition(skeletonGraphic.transform, positionScale, positionOffset);

Note that you can leave out the attachment in the call (targetAttachment in your code) since it's only the bone that matters.

@vampodav In regards to whether the final coords shall be in UI coordinates or world coordinates, I'm not quite sure I understand what your desired target space is. In any case, looking at the implementation of BoneFollowerGraphic.cs might help.