---
title: AnimationClipExtensions
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/animationclipextensions
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/animationclipextensions.md
last_updated: 2026-11-30
generated_at: 2026-11-30T21:16:09.407Z
locale: en-us
---

# AnimationClipExtensions

> Extension methods for animation clips that give access to the clip data used for sampling.

## Definition

* **Type:** Class
* **Namespace:** [Unity.Animations](/engine/7000.0/script-reference/unity/animations.md)
* **Assembly:** [UnityEngine.AnimationCoreModule](/engine/7000.0/script-reference/modules/unityengine-animationcoremodule.md)

```csharp
public static class AnimationClipExtensions
```

## Remarks

Call [AnimationClipExtensions.ToClipSampler](/engine/7000.0/script-reference/unity/animations/animationclipextensions/toclipsampler.md) to sample an animation clip into an [AnimationStream](/engine/7000.0/script-reference/unity/animations/animationstream.md). Call [AnimationClipExtensions.ToClipReference](/engine/7000.0/script-reference/unity/animations/animationclipextensions/toclipreference.md) to get a reference to the clip data of an animation clip. Use the reference, for example, to read the length of the clip or to store the reference in a component. Read the data through [BlobObjectReference\<T>.Value](/engine/7000.0/script-reference/unityengine/blobobjectreference1/value.md), also from jobs.

The following example uses the `Unity.Animations`, `Unity.Collections`, `Unity.Entities`, `Unity.IntegerTime`, and `UnityEngine` namespaces. It builds a rig that has one float channel and creates a [ClipSampler](/engine/7000.0/script-reference/unity/animations/clipsampler.md) from an animation clip. It then samples the clip into an animation stream. The example animates the `intensity` field of the `SampleClipExampleTarget` component. To run the example, add a `MonoBehaviour` named `SampleClipExampleTarget` that has a `float` field named `intensity`, or replace the component and the field with the ones that your animation clip animates.

Additional Resources: [ClipSampler](/engine/7000.0/script-reference/unity/animations/clipsampler.md)

## Examples

```csharp
// This example samples the intensity field that a clip animates at a given time and returns the sampled value.
public static float SampleIntensity(AnimationClip animationClip, float time)
{
    // Describe the animated field in a rig, so that the animation stream has a slot for it.
    using RigBuilder rigBuilder = new RigBuilder(Allocator.Temp);
    // The empty path means that the animated component is on the root object. The last argument is the
    // default value.
    rigBuilder.Add(FloatChannel.Create(
        "", typeof(SampleClipExampleTarget), nameof(SampleClipExampleTarget.intensity), 0f));
    using BlobObjectReference<RigDefinition> rigDefinition =
        rigBuilder.ToRigDefinition();

    // Create a sampler for the clip and the rig, from the main thread.
    // Keep the sampler between samples of the same clip to sample faster.
    using ClipSampler sampler = animationClip.ToClipSampler(ref rigDefinition.Value, Allocator.Persistent);
    // Stop if the sampler isn't created, for example when the animation clip is null.
    if (!sampler.IsCreated)
    {
        return 0f;
    }

    // Create the animation stream that receives the sampled values. The stream owns its buffer.
    AnimationStream stream = AnimationStream.Create(ref rigDefinition.Value, Allocator.Temp);

    // Sample the clip at the given time. The sample overwrites the content of the stream.
    sampler.Sample(ref stream, new DiscreteTime(time));
    float intensity = stream.GetFloat(0);

    // Dispose the stream explicitly, because a using declaration can't be passed by reference.
    stream.Dispose();

    // For a clip that goes from 0 to 10 over one second, the sample at 0.5 seconds is 5.
    return intensity;
}
```

## Static Methods

| Method                                                                                                         | Description                                                                                                                        |
| -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [ToClipReference](/engine/7000.0/script-reference/unity/animations/animationclipextensions/toclipreference.md) | Acquires a reference to the sampling data of an animation clip.                                                                    |
| [ToClipSampler](/engine/7000.0/script-reference/unity/animations/animationclipextensions/toclipsampler.md)     | Creates a [ClipSampler](/engine/7000.0/script-reference/unity/animations/clipsampler.md) that samples an animation clip for a rig. |
