Only the clips themselves get updated, the Graph isn't touched.
[Unity] Mecanim now supported in Unity 4 and 5!
Okay, that's what I was hoping
thanks Mitch!
I've got most of it working, but I've moved onto events and had another question. It seems that the general technique for managing events is interfacing via the AnimationState, but I don't know how to query for that when using a SkeletonAnimator.
I am able to receive Spine events as Unity/mecanim style events on the mecanim timeline
though, admittedly, assuming the string name of the event as a hardcoded function call seems a little bizarre, perhaps they should at least be prefixed with "SpineEvent_" for clarity/name-collision safety? Or maybe use something more similar to the way you do your Spine attributes, with a [SpineStringEvent("EventName", "FuncMapping")] style approach?
Anyways, how would you go about getting the Complete/End generic events without AnimationState? Or, maybe a better question: how would you get the AnimationState from SkeletonAnimator?
Also
unrelated: it seems that if you have an animation without any textures in it (a guide animation), the Unity plugin will fail to produce any of the skeleton data exports from the json. Putting a junk texture in there seems to fix the problem, probably just a minor bug.
Thanks again, this has been very helpful!
Jeremy
Err I missed something in my post
Events are handled the Unity way. The dummy clips also contain AnimationEvent that are mostly equivalent to spine events. TL;DR it uses sendmessage
Anyways, how would you go about getting the Complete/End generic events without AnimationState? Or, maybe a better question: how would you get the AnimationState from SkeletonAnimator?
In unity 5 you can write graph behaviors for mecanim. Good hunting heh
AnimationState does not exist within Skeleton Animator
Okay, I'll use unity graph behaviors for the complete (OnStateEnter) and end (OnStateExit) events.
So I'm seeing a lot of weird twitchy graphical behaviors (such as flipping on the x-axis in the middle of an animation) that I don't see when using a standard skeleton animation. Is there something that I may have misconfigured? Or maybe you have an updated build with some bug fixes?
Oops
nevermind about the twitchy behavior, it was something I had misconfigured. I believe this was caused when I mistakenly had some blending in one of my transitions, causing some very strange results.
Thanks ~ things are looking good with this integration, I like being able to use u5's state machines in my project!
Hi jeremy,
Can you go a bit into details what the problem was and how you solved it?
I seem to have some twitchy behaviors too (flipping X axis). I can indeed pinpoint it to having blending in the mecanim setup.
However, I actually DO want to have blending enabled when switching between animations, so I'm wondering if you managed to somehow have them without the glitches?
I basically turned blending off in mecanim for now to fix any animation weirdness. I'm still not entirely sure what the dummy anims are doing and if blending should actually work via mecanim. I assume the blending could be handled by the Spine animation engine, but I'm not sure if mecanim is able to feed Spine enough information for it to operate properly
this was noted earlier as an issue with mecanim integration in u4.x, maybe u5 solved the problem. Obviously, Mitch would have a lot greater insight here, and maybe lay out some best practices.
Blending works great for Pos/Rot/Scale and well enough for Attachment keys... I've seen some wonkiness in the others. I haven't had a chance to really use the mecanim stuff in one of my own projects but I'll take a look at it sooner or later.
Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
Animation blending glitches fix.
Check animator state info and apply only that is valid.
Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
Always apply attachment animation is better for timing, layer mixing.
I might be missing something obvious, but it seems like there's something wrong with the mecanim animations generated by spine.
Upon dragging in the files in unity, the skeleton is generated automatically as it should. I went ahead and clicked "Generate Mecanim Controller". Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
The controller get's generated perfectly fine, with the one animation we have inside as it should.
I then right-click the skeleton and select Spine > Instantiate( Mecanim ), which also generates a correct gameobject ( I presume) Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
However, when looking at the animator window, there are no states. Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
Same story for the animations window Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
I guessed I could just drag in the animation from the animator asset file, but then I end up with some missing stuff, and there is no animation visible. Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
Any idea what I could be doing wrong?
Thanks!
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)
Mitch a écritWorking 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.
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.
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:
Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
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 a écrit@[supprimé] 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.
Image supprimée en raison de l'absence de support de HTTPS. | Afficher quand même
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 ...
Mitch a écritAh 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?
Hello! This is a two year old thread.
This is the new way to instantiate: [New Feature] Drag and Drop to instantiate
Pharan a écritHello! 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.