From 43e1d624dd1d46041e0444a9585b702a4deb01ab Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 19 Jul 2024 12:37:44 +0200 Subject: [PATCH] [unity] Fixed wrong SkeletonUtilityBone position when used with RootMotion. Closes #2582. --- CHANGELOG.md | 2 + .../RootMotion/SkeletonRootMotionBase.cs | 7 +++ .../SkeletonUtility/SkeletonUtility.cs | 52 ++++++++----------- spine-unity/Assets/Spine/package.json | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f504cf432..daa028312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,6 +175,8 @@ - `SkeletonGraphicRenderTexture` example component: `protected RawImage quadRawImage` was changed to `protected SkeletonSubmeshGraphic quadMaskableGraphic` for a bugfix. This is only relevant for subclasses of `SkeletonGraphicRenderTexture` or when querying the `RawImage` component via e.g. `skeletonGraphicRenderTexture.quad.GetComponent()`. - Fixed a bug where when Linear color space is used and `PMA vertex colors` enabled, additive slots add a too dark (too transparent) color value. If you want the old incorrect behaviour (darker additive slots) or are not using Linear but Gamma color space, you can comment-out the define `LINEAR_COLOR_SPACE_FIX_ADDITIVE_ALPHA` in `MeshGenerator.cs` to deactivate the fix or just to skip unnecessary instructions. - Fixed SkeletonRootMotion components ignoring parent bone scale when set by transform constraints. Using applied scale of parent bone now. If you need the old behaviour, comment out the line `#define USE_APPLIED_PARENT_SCALE` in SkeletonRootMotionBase.cs. + - Fixed SkeletonUtility callback update order when used with SkeletonRootMotion components so that the position when following a bone is updated after SkeletonRootMotion clears root-bone position. The order of SkeletonUtilityBone callbacks is changed to be later to achieve this. This is a breaking change in the unlikely case that you are using SkeletonRootMotion together with SkeletonUtility and subscribed to `UpdateLocal`, `UpdateWorld` or `UpdateComplete` yourself and relied on a certain callback order. One solution is to then resubscribe your own callback events accordingly by calling + `.UpdateLocal -= Callback; .UpdateLocal += Callback;`. - **Changes of default values** diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index 7559a7039..ddcdf1361 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -183,6 +183,13 @@ namespace Spine.Unity { skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild; skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild; + + SkeletonUtility skeletonUtility = GetComponent(); + if (skeletonUtility != null) { + // SkeletonUtilityBone shall receive UpdateLocal callbacks for bone-following after root motion + // clears the root-bone position. + skeletonUtility.ResubscribeEvents(); + } } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs index 749a81eae..910a8fa69 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs @@ -238,8 +238,27 @@ namespace Spine.Unity { bool needToReprocessBones; public void ResubscribeEvents () { - OnDisable(); - OnEnable(); + if (skeletonRenderer != null) { + skeletonRenderer.OnRebuild -= HandleRendererReset; + skeletonRenderer.OnRebuild += HandleRendererReset; + } else if (skeletonGraphic != null) { + skeletonGraphic.OnRebuild -= HandleRendererReset; + skeletonGraphic.OnRebuild += HandleRendererReset; + skeletonGraphic.OnPostProcessVertices -= UpdateToMeshScaleAndOffset; + skeletonGraphic.OnPostProcessVertices += UpdateToMeshScaleAndOffset; + } + + if (skeletonAnimation != null) { + skeletonAnimation.UpdateLocal -= UpdateLocal; + skeletonAnimation.UpdateWorld -= UpdateWorld; + skeletonAnimation.UpdateComplete -= UpdateComplete; + + skeletonAnimation.UpdateLocal += UpdateLocal; + if (hasOverrideBones || hasConstraints) + skeletonAnimation.UpdateWorld += UpdateWorld; + if (hasConstraints) + skeletonAnimation.UpdateComplete += UpdateComplete; + } } void OnEnable () { @@ -259,23 +278,8 @@ namespace Spine.Unity { skeletonGraphic != null ? skeletonGraphic.GetComponent() : GetComponent(); } - - if (skeletonRenderer != null) { - skeletonRenderer.OnRebuild -= HandleRendererReset; - skeletonRenderer.OnRebuild += HandleRendererReset; - } else if (skeletonGraphic != null) { - skeletonGraphic.OnRebuild -= HandleRendererReset; - skeletonGraphic.OnRebuild += HandleRendererReset; - skeletonGraphic.OnPostProcessVertices -= UpdateToMeshScaleAndOffset; - skeletonGraphic.OnPostProcessVertices += UpdateToMeshScaleAndOffset; - } - - if (skeletonAnimation != null) { - skeletonAnimation.UpdateLocal -= UpdateLocal; - skeletonAnimation.UpdateLocal += UpdateLocal; - } - CollectBones(); + ResubscribeEvents(); } void Start () { @@ -360,18 +364,6 @@ namespace Spine.Unity { } hasConstraints |= constraintComponents.Count > 0; - - if (skeletonAnimation != null) { - skeletonAnimation.UpdateWorld -= UpdateWorld; - skeletonAnimation.UpdateComplete -= UpdateComplete; - - if (hasOverrideBones || hasConstraints) - skeletonAnimation.UpdateWorld += UpdateWorld; - - if (hasConstraints) - skeletonAnimation.UpdateComplete += UpdateComplete; - } - needToReprocessBones = false; } else { boneComponents.Clear(); diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index 07004553a..bfc24e12b 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core.", - "version": "4.2.79", + "version": "4.2.80", "unity": "2018.3", "author": { "name": "Esoteric Software",