• Unity
  • Root motion Mecanim

So we can hope, Spine will receive root motion? 😛

Related Discussions
...

Think you can whip something up, Pharan? 🙂

@Pharan, We added 3 vars to skeletonUtilityBone which we poll.

public Vector2 m_StoredBonePos = Vector2.zero;
public bool m_DisablePositionChange = false;
public bool m_DidUpdate = false;

Where a component which we add to the root bone sets DisablePositionChange to true

then in update we need store the bone pos and set back to 0

Doupdate()
{
...
   float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;
            if ((bone.x != 0 || bone.y != 0))//store
            {
                m_DidUpdate = true;
                m_StoredBonePos = new Vector2(bone.x, bone.y);
            }
...
if (position)
                {
                    if (!m_DisablePositionChange)//check if it should move, if not reset it to 0
                        cachedTransform.localPosition = new Vector3(bone.x, bone.y, 0);
                    else
                    {
                        bone.x = 0;
                        bone.y = 0;
                    }
                }

}

But you also need to turn off mixing between animations for the rootbone.
TranslateTimeline.Apply:

override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> firedEvents, float alpha, bool setupPose, bool mixingOut) {
         Bone bone = skeleton.bones.Items[boneIndex];

if (boneIndex == 0)
                alpha= 1;
...

12 Dec 2016, 10:07


now you can just plug into the stored position, and move the character by that amount

@BinaryCats I saw in the other thread about Mecanim you said that you moved away from Mecanim right? Is root motion easier without it? I saw a few script in this forum about this. I decided to use Mecanim because we have a complex movement system and thought its easier do define this with Mecanim. If you say that its without easier, I'll give it a try to programm it.

partially, We turn rootmotion on and of with events. With mecanim you have to write code to listen to spine events yourself. (you get events through the mechanim system, but not all the data (its either float,int or string, not all)

I don't believe we ever used the rootmotion which mecanim and unity animator things provides for 3d models. and I'm not sure if it would ever work. other than the event stuff, it would just be the same.

My advice for mecanim would depend on your game, if its a big game, ild suggest not to use it (it becomes hard to manage), if its small there is no harm in trying to do it, even if you have to scrap it further down the line. - its important to note we where not at the start of the project when we integrated mecanim and that would have contributed to the nightmare

So, is there any nearly perfect running solution on this? With SkeletonAnimation or SkeletonAnimator (I think I can change if needed). I really need this, or how did all other Spine devs this? Cannot be the only one who need not "inplace" animations. Or there must be a solution to transform smoothly in Unity (inplace animation).

i have posted in this thread the files you need to change

I'll give it a try, thanks. This is with Mecanim right?

4 mois plus tard

Hi guys,

I'm trying to implement the bit of code that @BinaryCats (thank you a thousand times for that) wrote, but I'm struggling making it work because I'm a beginner on Spine and the Spine-Unity lib.

I think I have an issue with the setup of the root bone animation maybe :/
I firstly made the main animation on the static character, then I made the root bone moving on the Y axis (my game is a vertical scroller).

Then I imported my character on Unity and in the hierarchy as a SkeletonAnimation. I Setted the default AnimationName as the one I created. And when I push Play I see that my character actually translate on the Y axis but the transform of my character GameObject doesn't have his y axis changing by some wizardry i'm not fimiliar with!

I then added a SkeletonUtility and then spawned a Hierarchy (follow) to fill the RootBone public property with my actual root bone. I could then get a root bone gameobject with a SkeletonUtilityBone component already attached.

I tried after to make the changes ahead on SkeletonUtilityBone and the TranslateTimeline.Apply method, but I still see my character moving up even if my bone get its ax and ay properties set to 0 in the DoUpdate function 🙁

So I'm now looking for someone to help me pointing out my mistake(s) so I can finally get a static object that I can move programmatically by retrieving the StoredBonePos Vector2.

Thank you in advance folks!

Thanks a lot Nate and Pharan, this script works like a charm!
Do you plan to integrate it in the 3.6 version ? I didn't see any mention of that in the release note ^^

Great! :happy: Yes, we should include it in spine-unity so it is more discoverable.