---
title: AnimationStreamMask
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/animationstreammask
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/animationstreammask.md
last_updated: 2026-11-30
generated_at: 2026-11-30T21:11:28.446Z
locale: en-us
---

# AnimationStreamMask

> An AnimationStreamMask is a data proxy to a Rig's WeightData. It can be used to read and write individual weight mask rig channels.

## Definition

* **Type:** Struct
* **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 ref struct AnimationStreamMask
```

## Remarks

A mask is a `ref struct`, so it lives only on the stack, for the scope where you create it. It can't be a field of a class, of a job or of another struct. To use a mask in a job, store its buffer, or the [WeightMaskSampler](/engine/7000.0/script-reference/unity/animations/weightmasksampler.md), in the job and create the mask in the `Execute` method of the job.

How the safety system checks a mask depends on how you create it:

* [AnimationStreamMask.Create](/engine/7000.0/script-reference/unity/animations/animationstreammask/create.md) allocates a buffer that the mask owns. Call [AnimationStreamMask.Dispose](/engine/7000.0/script-reference/unity/animations/animationstreammask/dispose.md) to free it, for example with a `using` statement.

* [AnimationStreamMask.Create](/engine/7000.0/script-reference/unity/animations/animationstreammask/create.md) and [AnimationStreamMask.CreateReadOnly](/engine/7000.0/script-reference/unity/animations/animationstreammask/createreadonly.md) return a view of the array that uses the safety handle of the array. The array keeps its memory, and you dispose it as usual.

* [AnimationStreamMask.CreateReadOnly](/engine/7000.0/script-reference/unity/animations/animationstreammask/createreadonly.md) returns a view of the sampler that uses the safety handle of the sampler. The sampler keeps its memory, and you dispose it as usual.

If safety checks are enabled, a mask throws an `ObjectDisposedException` if you use it after you dispose its memory.

The following example is a `MonoBehaviour` that plays a base clip and adds an additive clip on the upper body of a character. Each frame, it blends the additive clip with a stream mask that views the weights of a weight mask.

The last code block is the Burst-compiled function that writes the pose to the transforms. The function isn't part of the API, so copy it into your project.

\`\`\<!\[CDATA\[using Unity.Burst; using Unity.Collections; using Unity.Mathematics; using UnityEngine;

namespace Unity.Animations.DocumentationExamples \{ // Writes the pose in a stream to the transform handles that // RigDefinitionUtility.BindTransforms outputs. Entry index of the // handles is the transform of bone index. \[BurstCompile] public static class WriteTransformsUtility \{ // A Burst-compiled static method runs on the main thread, so it // writes the transforms without the cost of scheduling a job. \[BurstCompile] public static void WriteTransforms( in AnimationStream stream, in NativeArray\<TransformHandle> transforms) \{ for (int i = 0; i \< transforms.Length; ++i) \{ // The entry of a bone that has no transform is None, and a // destroyed transform is no longer valid. TransformHandle transform = transforms\[i]; if (!transform.IsValid()) \{ continue; }

stream.GetLocalToParentTRS( i, out float3 translation, out quaternion rotation, out float3 scale); transform.SetLocalPositionAndRotation(translation, rotation); transform.localScale = scale; } } } } ]]>

## Examples

```csharp
using Unity.Collections;
using Unity.IntegerTime;
using UnityEngine;

namespace Unity.Animations.DocumentationExamples
{
    // This example plays a base clip, such as a walk, and adds an additive clip, such as a breathing motion, on the
    // bones that a mask selects, such as the upper body. The additive clip holds the difference from its reference pose,
    // so it adds the breathing to whatever pose the base clip plays. Assign two clips that animate the transforms under
    // the GameObject of this component, with paths relative to this GameObject. Assign the skeleton root, the top bone
    // of the skeleton, a direct child of this GameObject. The mask selects the bone at the mask root path and the bones
    // below it.
    public class AdditiveLayerExample : MonoBehaviour
    {
        public AnimationClip baseClip;
        public AnimationClip additiveClip;
        public Transform skeletonRootTransform;
        public string maskRootPath = "Hips/Spine";
        [Range(0f, 1f)] public float additiveWeight = 1f;

        BlobObjectReference<RigDefinition> m_RigDefinition;
        BlobObjectReference<WeightMask> m_WeightMask;
        WeightMaskSampler m_WeightMaskSampler;
        NativeArray<TransformHandle> m_BoneTransforms;
        ClipSampler m_BaseSampler;
        ClipSampler m_AdditiveSampler;
        float m_Time;

        void OnEnable()
        {
            if (baseClip == null || additiveClip == null || skeletonRootTransform == null)
                return;

            // Build one rig for both clips, so that both clips sample into streams of the same rig. The reference keeps
            // the rig definition alive until you dispose it.
            using RigBuilder rigBuilder = RigBuilder.Create(
                transform, skeletonRootTransform, new[] { baseClip, additiveClip }, Allocator.Temp);
            m_RigDefinition = rigBuilder.ToRigDefinition();
            RigDefinitionUtility.BindTransforms(
                ref m_RigDefinition.Value, transform, Allocator.Persistent, out m_BoneTransforms);
            m_BaseSampler = baseClip.ToClipSampler(ref m_RigDefinition.Value, Allocator.Persistent);
            m_AdditiveSampler = additiveClip.ToClipSampler(ref m_RigDefinition.Value, Allocator.Persistent);

            // A bone that the mask doesn't list gets the default transform weight, here 0, so only the bones below the
            // mask root get the additive clip. A float, int, or entity ID channel that the mask doesn't list gets the
            // default generic weight. Because propagateWeight is true, the weight of the mask root also applies to
            // each bone below it, such as the head and the arms below the spine.
            using WeightMaskBuilder maskBuilder = new WeightMaskBuilder(
                Allocator.Temp, defaultTransformWeight: 0f, defaultGenericWeight: 1f);
            maskBuilder.SetTransformMask(new StringHash(maskRootPath), 1f, propagateWeight: true);

            // The weight mask stores identifiers, not indices, so it doesn't depend on a rig. Keep it to resolve it for
            // other rigs, for example characters that share the bone names.
            m_WeightMask = maskBuilder.ToWeightMask();

            // Resolve the weight mask for this rig. The sampler has one weight for each channel of the rig. Creating it
            // is expensive, so create it once. To mask more characters of the same rig, call Clone on it.
            m_WeightMaskSampler = m_WeightMask.Value.ToWeightMaskSampler(ref m_RigDefinition.Value, Allocator.Persistent);
            m_Time = 0f;
        }

        void OnDisable()
        {
            // Dispose the samplers before the rig definition that they use.
            if (m_BaseSampler.IsCreated)
                m_BaseSampler.Dispose();
            if (m_AdditiveSampler.IsCreated)
                m_AdditiveSampler.Dispose();
            if (m_WeightMaskSampler.IsCreated)
                m_WeightMaskSampler.Dispose();
            m_WeightMask.Dispose();
            if (m_BoneTransforms.IsCreated)
                m_BoneTransforms.Dispose();
            m_RigDefinition.Dispose();
        }

        void Update()
        {
            m_Time += Time.deltaTime;
            ApplyPose(m_Time);
        }

        // Samples both clips at a time, adds the additive clip to the base clip with the mask, and writes the pose to
        // the transforms.
        public void ApplyPose(float time)
        {
            if (!m_BaseSampler.IsCreated || !m_AdditiveSampler.IsCreated)
                return;

            AnimationStream output = AnimationStream.Create(ref m_RigDefinition.Value, Allocator.Temp);
            m_BaseSampler.Sample(ref output, new DiscreteTime(time));

            // SampleAdditive writes the difference between the clip and its reference pose: translations, scales and
            // floats minus the reference values, and rotations relative to the reference rotations.
            AnimationStream additive = AnimationStream.Create(ref m_RigDefinition.Value, Allocator.Temp);
            m_AdditiveSampler.SampleAdditive(ref additive, new DiscreteTime(time));

            // The stream mask views the weights of the weight mask sampler. It doesn't own memory. The weight of each
            // channel is additiveWeight multiplied by its weight in the mask. A channel with a weight of 0 keeps the
            // base pose.
            AnimationStreamMask mask = AnimationStreamMask.CreateReadOnly(ref m_RigDefinition.Value, m_WeightMaskSampler);
            output.BlendAdditive(additive, additiveWeight, mask);

            // Write the pose to the transforms with a Burst-compiled function. The function isn't part of the API,
            // so copy it into your project.
            WriteTransformsUtility.WriteTransforms(output, m_BoneTransforms);

            // Dispose the streams explicitly, because a using declaration can't be passed by reference.
            additive.Dispose();
            output.Dispose();
        }
    }
}
```

## Properties

| Property                                                                                                                     | Description                                                                                                                                                           |
| ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [BoneCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/bonecount.md)                               | Returns the total bone count.                                                                                                                                         |
| [EntityIdCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/entityidcount.md)                       | The number of entity ID channels that the mask holds a weight for.                                                                                                    |
| [FloatCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/floatcount.md)                             | The number of generic float channels in the mask.                                                                                                                     |
| [IntCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/intcount.md)                                 | The number of generic integer channels in the mask.                                                                                                                   |
| [IsCreated](/engine/7000.0/script-reference/unity/animations/animationstreammask/iscreated.md)                               | Whether the mask has a rig definition and a buffer.                                                                                                                   |
| [IsReadOnly](/engine/7000.0/script-reference/unity/animations/animationstreammask/isreadonly.md)                             | Whether the mask is read-only.                                                                                                                                        |
| [RigDefinition](/engine/7000.0/script-reference/unity/animations/animationstreammask/rigdefinition.md)                       | The [AnimationStreamMask.RigDefinition](/engine/7000.0/script-reference/unity/animations/animationstreammask/rigdefinition.md) that describes the layout of the mask. |
| [RotationCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/rotationcount.md)                       | The number of rotation channels in the mask.                                                                                                                          |
| [ScaleCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/scalecount.md)                             | The number of scale channels in the mask.                                                                                                                             |
| [TranslationCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/translationcount.md)                 | The number of translation channels in the mask.                                                                                                                       |
| [WeightDataChunkCount](/engine/7000.0/script-reference/unity/animations/animationstreammask/weightdatachunkcount.md)         | Returns the total weight data chunk count                                                                                                                             |
| [WeightDataChunks](/engine/7000.0/script-reference/unity/animations/animationstreammask/weightdatachunks.md)                 | Returns the weight data as float4 chunks.                                                                                                                             |
| [WeightDataChunksReadOnly](/engine/7000.0/script-reference/unity/animations/animationstreammask/weightdatachunksreadonly.md) | The weight data of the mask, as a read-only array of `float4` chunks.                                                                                                 |

## Methods

| Method                                                                                                               | Description                                                                                        |
| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| [Clear](/engine/7000.0/script-reference/unity/animations/animationstreammask/clear.md)                               | Clear all weight mask values.                                                                      |
| [CopyFrom](/engine/7000.0/script-reference/unity/animations/animationstreammask/copyfrom.md)                         | Copies all the data from the specified AnimationStreamMask into this AnimationStreamMask.          |
| [Dispose](/engine/7000.0/script-reference/unity/animations/animationstreammask/dispose.md)                           | Releases the mask.                                                                                 |
| [GetBoneWeights](/engine/7000.0/script-reference/unity/animations/animationstreammask/getboneweights.md)             | Returns the specified bone weights as a float3 containing translation, rotation and scale weights. |
| [GetEntityIdWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/getentityidweight.md)       | Returns the weight of the specified entity ID channel.                                             |
| [GetFloatWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/getfloatweight.md)             | Returns the specified float weight.                                                                |
| [GetIntWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/getintweight.md)                 | Returns the specified integer weight.                                                              |
| [GetRotationWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/getrotationweight.md)       | Returns the specified rotation weight.                                                             |
| [GetScaleWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/getscaleweight.md)             | Returns the specified scale weight.                                                                |
| [GetTranslationWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/gettranslationweight.md) | Returns the specified translation weight.                                                          |
| [SetAllWeightsTo](/engine/7000.0/script-reference/unity/animations/animationstreammask/setallweightsto.md)           | Set all weight mask values to the specified weight.                                                |
| [SetBoneWeights](/engine/7000.0/script-reference/unity/animations/animationstreammask/setboneweights.md)             | Sets bone weights using a float3 containing translation, rotation and scale weights.               |
| [SetEntityIdWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/setentityidweight.md)       | Sets the weight of the specified entity ID channel.                                                |
| [SetFloatWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/setfloatweight.md)             | Sets the weight of a specific float.                                                               |
| [SetIntWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/setintweight.md)                 | Sets the weight of a specific integer.                                                             |
| [SetRotationWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/setrotationweight.md)       | Sets the weight of a specific rotation.                                                            |
| [SetScaleWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/setscaleweight.md)             | Sets the weight of a specific scale.                                                               |
| [SetTranslationWeight](/engine/7000.0/script-reference/unity/animations/animationstreammask/settranslationweight.md) | Sets the weight of a specific translation.                                                         |

## Static Methods

| Method                                                                                                   | Description                                                                                                                                                     |
| -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Create](/engine/7000.0/script-reference/unity/animations/animationstreammask/create.md)                 | Creates a read-write AnimationStreamMask that allocates and owns its buffer.                                                                                    |
| [CreateReadOnly](/engine/7000.0/script-reference/unity/animations/animationstreammask/createreadonly.md) | Creates a read-only AnimationStreamMask that reads the weights of a [WeightMaskSampler](/engine/7000.0/script-reference/unity/animations/weightmasksampler.md). |
