CheMBurN

Bought spine recently - quite a learning curve but excellent bit of software!

How would I be able to stop the interpolation of my animations via script? I'm porting my animations to spine and Im using the spine skeleton mecanim method to make it easier and I don't have a spine reference anywhere in my code - just dragging and dropping the motion .anim files created into the state machine I built.

Is there a way to turn off interpolation in the animations (similar to turning off the interpolation in the playback settings)?

Edit: So I ran into a problem. From what it looks like, I cannot use one animation state machine (animator) to manage several skeletons when using skeleton mecanim, can I?
CheMBurN
  • Postovi: 2

Harald

Thanks for your kind words!
CheMBurN je napisao/la:How would I be able to stop the interpolation of my animations via script? I'm porting my animations to spine and Im using the spine skeleton mecanim method to make it easier and I don't have a spine reference anywhere in my code - just dragging and dropping the motion .anim files created into the state machine I built.
When using SkeletonMecanim, animation timing and blending is performed by the Mecanim engine, SkeletonMecanim then uses the resulting weight values to apply the animations. Could you please explain what you want to achieve, and how you adjusted animation blending of your Mecanim state machine via script before switching to Spine?
CheMBurN je napisao/la:Edit: So I ran into a problem. From what it looks like, I cannot use one animation state machine (animator) to manage several skeletons when using skeleton mecanim, can I?
You should be able to use an AnimatorOverrideController to create one master controller (where you define the whole logic and setup transitions) and then create an AnimatorOverrideController that overrides the used animations with the animations of another skeleton.
Avatar
Harald

Harri
  • Postovi: 3914

CheMBurN

Harald je napisao/la:
Thanks for the reply!

Sorry I was a bit unclear before, I was using sprite based animation before I got spine and I when I said mecanim I meant I was simply using the animation state machine I had built previously and replacing the spritesheet motions with the spine mecanim motions that it creates (instead of using the controller created by spine itself) to save time.

My question was some of my animations look better when not interpolated (like IK switching from positive to negative) so I was wondering if there is a way to stop interpolation via an option in the runtime or even in spine? Basically for the animation to go frame to frame?

I believe I could do this by creating stepped curves for the 'main' frames in animate mode but wouldn't I then need to key everything in the frames in between (since the animation would only play for frames that has keys in them)? I read on your forums that that's not great for performance. Sorry in advance if my understanding is lacking.
Harald je napisao/la:You should be able to use an AnimatorOverrideController to create one master controller (where you define the whole logic and setup transitions) and then create an AnimatorOverrideController that overrides the used animations with the animations of another skeleton.
Interesting! Although trawling through forums I realized the best way would be to put in everything in one skeleton and it seems to work for now. If somethings changes Ill try this out
CheMBurN
  • Postovi: 2

Harald

CheMBurN je napisao/la:[..] is a way to stop interpolation via an option in the runtime or even in spine
I'm not sure I completely understand what you are trying to achieve. Is your situation similar to e.g. transitioning from an animation left with an IK target bone on the left side to another animation right with the same IK target being located on the right? And that you then want to control the length (duration, number of transition frames) of this transition via scripting? If this is the case, the above reply still holds true, it does not matter if you key every frame of the bone location or only two, when transitioning from one animation to another the mix will be (1-t) * left(time) + t * right(time). You will need to adjust the Mecanim Transition duration (the transition arrows in the Animator window) if you want it to be shorter.
CheMBurN je napisao/la:Interesting! Although trawling through forums I realized the best way would be to put in everything in one skeleton and it seems to work for now.
It depends. Skin management will be easier for example when not having separate skeletons for every character.
Avatar
Harald

Harri
  • Postovi: 3914

herrkjeldsen

I'm also looking for a way to disable interpolation in Unity (as can be done in the Spine editor). Did you ever find a solution for this? :D
herrkjeldsen
  • Postovi: 4

Nate

Which setting in the Spine editor are you trying to mimic? Interpolated on the playback view?
Playback view - Spine User Guide: Interpolated
Avatar
Nate

Nate
  • Postovi: 11791

madbaek

Nate je napisao/la:Which setting in the Spine editor are you trying to mimic? Interpolated on the playback view?
Playback view - Spine User Guide: Interpolated
Okay, I'm not the writer of the post and this thread has been dead silent for several months, but I also want that unchecked-interpolated animation function without using the fixed timestep script(mainly because I'm using the mecanim too and the script doesn't work with mecanim). I think it would be okay if there's a json export option where every single frame of animation is keyed and every key is curved with constant when it is exported. Something like this image I uploaded.
constant.png
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
madbaek
  • Postovi: 5

Nate

You would not want so many keys at runtime. There is a computational cost to having many keys. The correct way is to adjust the time step.

Maybe there is a workaround for mechanim? @Harald, can the mechanim code adjust the time just before the animation is applied?
Avatar
Nate

Nate
  • Postovi: 11791

Harald

A simple solution which applies stepped update time to a Mecanim Animator in general is the following solution (also attached as a file at the end of this posting):
using UnityEngine;

public class SteppedMecanimUpdates : MonoBehaviour {
Animator animator;
float timeSinceStep = 0;
public float timeStep = 0.5f;

private void Awake () {
animator = this.GetComponent<Animator>();
}

private void Update () {
timeSinceStep += Time.deltaTime;
if (timeSinceStep > timeStep) {
float remainderTime = timeSinceStep % timeStep;
float appliedTime = timeSinceStep - remainderTime;
timeSinceStep = remainderTime;
animator.speed = appliedTime / Time.deltaTime;
} else
animator.speed = 0;
}
}
As an alternative, you could also modify the SkeletonMecanim code accordingly to apply animations at fixed time increments. The corresponding code can be found here in SkeletonMecanim.cs. You then need to forward the timestep configuration parameters accordingly.
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
Avatar
Harald

Harri
  • Postovi: 3914

madbaek

Harald je napisao/la:A simple solution which applies stepped update time to a Mecanim Animator in general is the following solution (also attached as a file at the end of this posting):
using UnityEngine;

public class SteppedMecanimUpdates : MonoBehaviour {
Animator animator;
float timeSinceStep = 0;
public float timeStep = 0.5f;

private void Awake () {
animator = this.GetComponent<Animator>();
}

private void Update () {
timeSinceStep += Time.deltaTime;
if (timeSinceStep > timeStep) {
float remainderTime = timeSinceStep % timeStep;
float appliedTime = timeSinceStep - remainderTime;
timeSinceStep = remainderTime;
animator.speed = appliedTime / Time.deltaTime;
} else
animator.speed = 0;
}
}
Thank you SO much! Your code is working as what I wanted!
madbaek
  • Postovi: 5

Harald

Glad to hear, thanks for your letting us know :).
Avatar
Harald

Harri
  • Postovi: 3914


Natrag na Unity