[EDIT: I solved this while posting the question, but I'll keep the answer here for anyone who needs it.]
Hi,
I'm doing a thing where a guy points his arm towards the mouse, and bends upper/lower arm to my needs, and this overrides the normal animation. This works fine.
After the arm is positioned, I position a gun (which is a separate Unity Gameobject) on the position of the hand. This is all done in UpdateLocal(), and the issue I'm having is that positioning of the gun happens 1 frame after the arm is rotated.
I have placed SkeletonAnimation at +200 and -10 in the Script Execution Order, but it didn't make any difference.
How can I synchronize this to happen at the exact same frame?
I suspect that
handBone.GetWorldPosition(transform)
doesn't get updated right away, after
armUpBone.SetLocalPosition
has been set. Can I force this update?
Here is a relevant part of the code:
void UpdateLocal(ISkeletonAnimation s) {
// Do stuff to calculate angles/positions
// [...]
// Set arm bones rotation and positions
armDownBone.rotation = armDownRotation + recoilArmDown + recoilArmUp;
armUpBone.rotation = armUpRotationAdjusted + 90 - armDownRotation + recoilArmUp;
armUpBone.SetLocalPosition(new Vector2(armUpBone.x + armUpPositionX, armUpBone.y + armUpPositionY));
// Set weapon position and rotation (This happens one frame later)
weaponTransform.position = handBone.GetWorldPosition(transform);
weaponTransform.eulerAngles = new Vector3(0,0,weaponRotationAdjusted);
}
I had to run UpdateWorldTransform(); like this, right after SetLocalPosition to make sure the LocalPosition was updated when read again from the line below.
skeletonAnimation.skeleton.UpdateWorldTransform();
For some reason, the docs on http://esotericsoftware.com/spine-runtime-skeletons#updateWorldTransform mentions it with lower case u on the method. Not sure why.
Hope it helps anyone, and Spine guys, you might have to check the documentation with the lower case of the method.
Thanks for an awesome tool 🙂