ToClipSampler(AnimationClip, ref RigDefinition, Allocator)
Creates a ClipSampler that samples an animation clip for a rig.
Read time 2 minutesLast updated 5 hours ago
Definition
- Type: Method
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
ToClipSampler(AnimationClip, RigDefinition, Allocator)
public static ClipSampler ToClipSampler(this AnimationClip clip, ref RigDefinition rig, Allocator allocator)
Parameters
The animation clip to sample. Can be null.
The rig of the animation streams to sample into. The sampler samples only the channels of the clip that the rig has.
The allocator to use for the memory of the sampler. Use a valid allocator. Allocator.Invalid and Allocator.None aren't allowed.
Returns
Type | Description |
|---|---|
| ClipSampler | The new sampler. Dispose it when you finish with it. ClipSampler.IsCreated is |
Remarks
Call this method from the main thread. The sampler acquires its own reference to the clip data. It keeps sampling that data even if the animation clip is destroyed, edited, or its data is replaced. To sample the edited clip, create the sampler again.
This method is expensive. It matches every curve of the clip with the channels of the rig, and the time it takes grows with the number of curves times the number of channels. Create one sampler for each pair of clip and rig, for example when your content loads, and keep it. When you need more samplers for the same clip and rig, for example one for each character, call ClipSampler.Clone on the sampler you kept. A clone only copies memory.
Dispose the sampler when you finish with it.
Only Generic clips are supported. If is a Humanoid clip, this method logs a warning once for the clip and returns a sampler that isn't created.
clip