Documentation

Unity Engine

Download Unity

Unity Engine

SampleExtractingRootMotion(ref AnimationStream, in TimerState)

Samples the clip with a clip timer, and removes the root motion from the pose, as an Animator does when it applies root motion.
Read time 2 minutesLast updated 4 hours ago

Definition

SampleExtractingRootMotion(AnimationStream, TimerState)

public void SampleExtractingRootMotion(ref AnimationStream stream, in TimerState timer)

Parameters

The stream to write the sampled channels to. It must have the rig that the sampler was created for.

The clip timer to sample, from Clip.ToTimerState.

Remarks

Use this method instead of ClipSampler.Sample when you move the character with the root motion of the clip from ClipSampler.SampleRootMotion. Otherwise the pose and the root motion both move the character.
The method samples the clip as
Sample
does, then expresses the root motion bone of the rig relative to the root transform of the clip at the time of the timer, as AnimationStream.ExtractRootMotionBone does with MotionOutput.RootTransform. When the clip has Loop Time and Loop Pose enabled, the method removes the root motion before it corrects the pose, so the correction doesn't move the root motion bone back.
The channels of the root motion bone that the clip doesn't animate take their default value in the rig, unlike with
Sample
, because the previous call replaced all the channels of that bone.
The method only changes the root motion bone when the clip animates the translation or rotation of that bone or of one of its parent bones. Otherwise, the pose doesn't move with the root motion, for example when only the
RootT
and
RootQ
curves of the clip give the root motion, and the method samples the clip as
Sample
does. By default, the root motion bone is the root bone of the rig. To choose another bone, set RigBuilder.RootMotionBoneId when you build the rig.