• Runtimes
  • [Unity] Mecanim now supported in Unity 4 and 5!

Mitch escribió

Working as intended. Hit the scene Play button after setting up your state. Sorry there isn't a way to scrub an animation using this mode, Unity might expose the things I need to make that happen eventually 🙂

The Dummy track is there simply to represent the duration of the Spine animation, so Mecanim doesn't try to blend as if its a 0 frame animation.

Events are also written to the standard Unity Animation event track as well. (IE: using SendMessage to fire events)

Oh right, in all my confusion it seems like I forgot to actually run the game haha. The animation doesn't seem to be looping though, I tried to enable "Loop time" and "Loop Pose" on the animationclip, but that didn't seem to make a difference.

I will probably stick to using the Skeleton Animation though and call SetAnimation() in a StateBehaviour on the corresponding state.

Related Discussions
...

Loop Time should work just fine... just enable it, go to File Save Project, and close/re-open unity a few times... Mecanim in 5.x is a totally buggy PoS.

14 días más tarde

Hey Mitch,

First of all great work! I learned quite a bit about Spine and Unity by just studying your code and the rest of the runtime. I ran into an issue, however, and I managed to fix it. So I'd like to get your opinion, and maybe include it officially.

I had the same problem as in this thread (http://esotericsoftware.com/forum/Adding-new-animations-to-Mecanim-Controller-4199). The expected behavior was to export from Spine directly into the Assets folder, and have the SkeletonData asset as well as the Mecanim controller asset reflect all changes made in Spine. After digging around a bit, adding this line to SkeletonBaker solved all my problems:

 Loading Image

You make an assumption about the path for the controller, because it is the place you created it in the first place. However, when I moved it to a different location, the resulting behavior is that objs is empty, because there is no controller at the assumed path.

Therefore animations get added again instead of updated, and animations that were deleted stay in the controller.

Hope this helps!

Regards,
Hadi


Rouven escribió

@[borrado] That didn't change anything, unfortunately. I have disabled and even removed my second (upper body) layer in the Animator, but the issues persist within the Base Layer.

I just noticed the keys that are dropped are only those that attach an image to a slot. All Scale/Rotate/Translate keyframes are applied just fine.

I experienced the same issue with dropping frames for attaching an image to a slot.

I'm on my phone right now, I can explain the reason for it later if you need it. Here's the line in spine c# runtime that you need to comment out to stop it from happening.

 Loading Image

Regards,
Hadi

@controllerPath fix
good catch - I missed that i wasn't updating the path string. (I don't move stuff around much heh)

@AttachmentTimeline patch
removing that line adds a lot of overhead. I'm considering creating a list of known patches/workarounds for issues w/ Mecanim and for Spine Unity in general that people can cherry pick and apply, but really have no business being in the main repo.

Hey I'm glad I could help.

Yeah I thought that line was a necessary optimization. The problem is that the way time and lasttime are calculated in SkeletonAnimator leaves gaps. So lasttime is not the actual last time value used in Spine, but slightly after.

If a key falls in the gap between the last time value, and the current lasttime value, that line drops it. I'm sure it can be solved without removing the optimization. I'll try simply storing it for one frame and using the value next frame.

Regards,
Hadi

Ah holy crap I never pushed that patch O_O

I fixed the lastTime calculation a while back. I'll deal with that a bit later. Sorry. Shows how much I use mecanim for anything ... 😐

2 años más tarde
Mitch escribió

Ah holy crap I never pushed that patch O_O

I fixed the lastTime calculation a while back. I'll deal with that a bit later. Sorry. Shows how much I use mecanim for anything ... 😐

@Mitch I've got the latest versions of spine-csharp & spine-unity.
But I don't see 'Instantiate' when I right click on SkeletonDataAsset.
Has something changed?

Pharan escribió

Hello! This is a two year old thread.
This is the new way to instantiate: http://esotericsoftware.com/forum/New-Feature-Drag-and-Drop-to-instantiate-6789

Thanks for the redirection!
I'm kind of not getting the most current workflow to utilize mecanim atm which gets me undesired results when

using UnityEngine;
using System.Collections;
using Spine.Unity;

public class SpineAnimationBehaviour : StateMachineBehaviour
{
    public string animClip;
    public int layer = 0;
    public float timeScale = 1f;
    private float normalizedTime;
    public float exitTime = .85f;
    public bool loop;

private SkeletonAnimation skeletonAnimation;
private Spine.AnimationState spineAnimationState;
private Spine.TrackEntry trackEntry;

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
    if (skeletonAnimation == null)
    {
        skeletonAnimation = animator.GetComponentInChildren<SkeletonAnimation>();
        spineAnimationState = skeletonAnimation.state;
    }

    trackEntry = spineAnimationState.SetAnimation(layer, animClip, loop);
    trackEntry.TimeScale = timeScale;

    normalizedTime = 0f;
}

override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
    normalizedTime = trackEntry.trackTime / trackEntry.trackEnd;

    if(!loop && normalizedTime >= exitTime)
    {
        animator.SetTrigger("transition");
    }
}

override public void OnStateExit (Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{

}

}

is what is attached to every single clip(as solitary states) in mecanim, therefore I can't really workout the blend tree.
What I want to achieve is just like any other mecanim workflow I'd get to play clips drag & drop without needing such script as above. Is there current workflow?

If you use SkeletonAnimator, you don't need the script above.

When you Instantiate your skeleton as a SkeletonAnimator, a Mecanim controller will be created, as well as several dummy AnimationClip assets as described in this old thread.
You would then lay out your Mecanim controller using the dummy animation clips like normal. Blend trees should work normally.

What SkeletonAnimator is doing at that point is just re-interpreting the state of the Mecanim state machine into poses for the skeleton.

Pharan escribió

If you use SkeletonAnimator, you don't need the script above.

When you Instantiate your skeleton as a SkeletonAnimator, a Mecanim controller will be created, as well as several dummy AnimationClip assets as described in this old thread.
You would then lay out your Mecanim controller using the dummy animation clips like normal. Blend trees should work normally.

What SkeletonAnimator is doing at that point is just re-interpreting the state of the Mecanim state machine into poses for the skeleton.

Damn, I didn't realize how dated those workflows I followed via Youtube were until this.
I even got my dummy animation clips by clicking the button that generates such.
I think I'd like to re-do the setup following your guide just now and then get back to you for the further question if I get stuck somewhere.
Thnks a lot again!
I think there should be more organized workflow guide as a document, though. If there already is and I just missed it, then it's either I've got dyslexia, or how they were posted were not that popping out because checking out the most recent workflow when it changes by reading forum post isn't the best thing to do such job DX, no offense.

None taken!

The Mecanim controller and dummy animation clips generated by clicking the button on the SkeletonData Asset are the same as when you instantiate the SkeletonAnimator for the first time. There should be no difference.

SkeletonAnimator/Mecanim integration is still less than ideal since Mecanim doesn't have all the necessary callbacks or expose as much of the internal states as we would have liked. This also makes it so that you can't see your skeleton animating in Edit mode, and still requires the dummy animation clips which can be confusing because new users expect there to be editable keys in the animation.

We're actually looking at whether it actually makes more sense to do away with the dummy animation clips and achieve integration via StateMachineBehaviours.

But as it is, SkeletonAnimator should work fine even if it's extensive as long as it's not doing anything that's also hackish.

Pharan escribió

None taken!

The Mecanim controller and dummy animation clips generated by clicking the button on the SkeletonData Asset are the same as when you instantiate the SkeletonAnimator for the first time. There should be no difference.

SkeletonAnimator/Mecanim integration is still less than ideal since Mecanim doesn't have all the necessary callbacks or expose as much of the internal states as we would have liked. This also makes it so that you can't see your skeleton animating in Edit mode, and still requires the dummy animation clips which can be confusing because new users expect there to be editable keys in the animation.

We're actually looking at whether it actually makes more sense to do away with the dummy animation clips and achieve integration via StateMachineBehaviours.

But as it is, SkeletonAnimator should work fine even if it's extensive as long as it's not doing anything that's also hackish.

If the results are identical either ways why are my clips not played without the script I mentioned above?
What could have gone wrong or done wrong if so?
I'm still not able to play any clips generated by the dummy clips in mecanim though my parameters are working correctly without the behaviour scripts attached to each clip that calls SetAnimation

edit: I found out I need to make 'SkeletonAnimator' not 'SkeletonAnimation. How I set up was with the latter. urgh... I can't tell how much extra work I'd need to to when I start over with SkeletonAnimator...