- Home /
animation.sample() usage
Hi I don't understand exacltly what does this function, but seems that it counld be something I'm looking for. Could someone tell me the concrete usage? Thanks!!
Answer by Paulius-Liekis · Feb 10, 2011 at 11:23 AM
It forces to sample current state of animations. "Sample animations" means: put character in the position defined by animation states. Sampling always happens between Update and LateUpdate automatically, but in some cases you might want to sample animations yourself. My most common case: I want to put character in pose of first frame some specific animation on Start, so I would do something like this:
void Start() { AnimationState state = animation["Aim"]; state.enabled = true; state.weight = 1; state.normalizedTime = 0;
animation.Sample();
}
There's a problem with this solution. You actually have to do "state.enabled = false" at the end or the animation will just play as normal.
void Start()
{
AnimationState state = animation["Aim"];
state.enabled = true;
state.weight = 1;
state.normalizedTime = 0;
animation.Sample();
state.enabled = false;
}
This will make the object start paused at the first frame of animation.
Your answer

Follow this Question
Related Questions
Changing the animation's "sample rate" property has no effect? 1 Answer
Problems sampling animation in editor 0 Answers
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
ragdoll recover 5 Answers