Sample
Samples the clip at the time of a clip timer. The method computes the value of each curve of the clip at that time, and overwrites the matching channels of the animation stream.
Read time 2 minutesLast updated 4 hours ago
Definition
- Type: Method
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
Sample(AnimationStream, TimerState)
Samples the clip at the time of a clip timer. The method computes the value of each curve of the clip at that time, and overwrites the matching channels of the animation stream.
public void Sample(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
The channels that the clip doesn't animate keep their value. To reset them to the rig defaults, call AnimationStream.ResetToDefaultValues before you sample.
The method samples the clip curves at TimerState.Time. Clip.ToTimerState adds the cycle offset when it creates the timer, so the timer time already includes the cycle offset. To sample at a playback time without a timer, use ClipSampler.Sample, which adds the cycle offset for you.
When the clip has Loop Time and Loop Pose enabled, the method also corrects the pose to close the gap between the first and last frames. The correction is zero at the start of TimerState.Range and grows until the end of the range, where the pose matches the pose of the first frame.
The sampler interpolates between the frames of the clip, so it doesn't snap the time to a frame. To play a clip backward, set a negative TimerState.TimeScale on the timer.
Sample(AnimationStream, DiscreteTime)
Samples the clip at a playback time. The method computes the value of each curve of the clip at that time, and overwrites the matching channels of the animation stream.
public void Sample(ref AnimationStream stream, DiscreteTime time)
Parameters
The stream to write the sampled channels to. It must have the rig that the sampler was created for.
The playback time in seconds from the start of the clip.
Remarks
The channels that the clip doesn't animate keep their value. To reset them to the rig defaults, call AnimationStream.ResetToDefaultValues before you sample.
This method already applies the Clip.LoopTime setting and the cycle offset of the clip to the playback time you pass. Don't pass the TimerState.Time of a clip timer, because the timer already applied the setting and the cycle offset to that time. To sample with a clip timer, use ClipSampler.Sample. For how and the cycle offset change the time, see Clip.ToTimerState.
LoopTimeLoopTimeThe sampler interpolates between the frames of the clip, so it doesn't snap the time to a frame. To play a clip backward, pass a playback time that decreases between calls.