grimbart_rene

hello spine team,
we want to use root motion for our next project but also do our own movement and collision checking.
to do so we only need something like a spine callback that tells us every animation update how much root motion it wants to apply without actually trying to apply it somehow.

i was able to achieve this by setting the Animation Update to "In Fixed Update", adding a fake Rigidbody2D component(disabled the "simulated" checkbox) and adding my own sub class of your SkeletonRootMotion component, that provides a root motion callback for other scripts:
public class SpineRootMotionTranslator : SkeletonRootMotion
{
public delegate void RootMotionUpdate(Vector2 displacement);
public event RootMotionUpdate OnRootMotionUpdate;

protected override void PhysicsUpdate(bool skeletonAnimationUsesFixedUpdate)
{
Vector2 rigidbodyDisplacement2D = new Vector2(this.rigidbodyDisplacement.x, this.rigidbodyDisplacement.y);

if (rigidbodyDisplacement2D != Vector2.zero)
{
if (this.OnRootMotionUpdate != null)
{
this.OnRootMotionUpdate(rigidbodyDisplacement2D);
}
}

this.previousRigidbodyRootMotion = this.rigidbodyDisplacement;
this.rigidbodyDisplacement = Vector2.zero;
}
}
This works really well for us but it's obviously just a hack to trick your code into thinking it applies root motion to a rigidbody.
And it is very likely to break once you make any changes to your code.

Can you please support something like this officially, so we will be able to update the spine integration in the future?
grimbart_rene
  • Posts: 5

Harald

Thanks for the input, that's a good idea! We will add such functionality, it should require just minimal modification. I assume it might already be done when removing the early return here and adding an optional callback instead:
SkeletonRootMotionBase.cs#L171.

We will perform some tests and release an update accordingly soon.
User avatar
Harald

Harri
  • Posts: 4164

grimbart_rene

Thanks Harald!
Yes probably the right place for animations updating in fixed update. But it would be great if other update modes were also supported.
grimbart_rene
  • Posts: 5

Harald

We have just pushed a commit that adds support for the desired callback delegates. From the changelog:
* Added SkeletonRootMotion callback delegates ProcessRootMotionOverride and PhysicsUpdateRootMotionOverride to customize how root motion is applied. The new property disableOnOverride determines whether the callback will be issued in addition or instead of normally applying root motion. Added property rootMotionScaleRotation to allow scaling rotational root-motion to match e.g. a 90 degree rotation to a custom target angle.
For more details, please check out the SkeletonRootMotionBase.cs source code:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.1/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs#L66-L90

Sorry that it took longer than expected. Along the way we discovered other issues regarding incorrect rigidbody 3D root motion regarding rotation (see this issue ticket), these have been fixed as well.

A new 4.1 spine-unity unitypackage is available for download here as usual:
spine-unity Download

We did our best to create a flexible override delegate solution which should cover pretty much any scenario. Please let us know if the additons suit your needs, or if you find anything missing.
User avatar
Harald

Harri
  • Posts: 4164

grimbart_rene

Thanks Harald, this looks very flexible indeed!
grimbart_rene
  • Posts: 5


Return to Unity