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

# Weight

> Weights the stream using a stream weight mask.

## Definition

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

## Weight(AnimationStream, float, AnimationStreamMask)

Weights the stream using a stream weight mask.

```csharp
public static void Weight(this ref AnimationStream stream, float weight, in AnimationStreamMask mask)
```

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The stream to modify. The method stores the result in this stream.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The weight to apply to the stream. The mask scales it for each channel.**** (\[AnimationStreamMask]\(/engine/7000.0/script-reference/unity/animations/animationstreammask)): The mask that scales the weight of each channel.

### Remarks

The method scales the translation, scale, and float values towards 0 and the rotations towards the identity rotation, by the weight of each channel. Use it on an additive stream, for example from [AnimationStreamBlendingExtensions.Delta](/engine/7000.0/script-reference/unity/animations/animationstreamblendingextensions/delta.md). On a pose, it also scales the bone lengths and the bone scales.

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 makes an additive pose from two poses at runtime, for example the difference between a leaning pose
    // and a neutral pose, and adds it to the pose of a base clip with a weight. Assign three 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 pose clip and the reference pose clip
    // give the poses at their first frame. The mask selects the bone at the mask root path and the bones below it.
    public class AdditivePoseExample : MonoBehaviour
    {
        public AnimationClip baseClip;
        public AnimationClip poseClip;
        public AnimationClip referencePoseClip;
        public Transform skeletonRootTransform;
        public string maskRootPath = "Hips/Spine";
        [Range(0f, 1f)] public float poseWeight = 1f;

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

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

            // Build one rig for the three clips, so that the 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, poseClip, referencePoseClip }, 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);

            // Sample the two poses at the first frame of their clips.
            ClipSampler poseSampler = poseClip.ToClipSampler(ref m_RigDefinition.Value, Allocator.Persistent);
            ClipSampler referenceSampler = referencePoseClip.ToClipSampler(
                ref m_RigDefinition.Value, Allocator.Persistent);
            AnimationStream pose = AnimationStream.Create(ref m_RigDefinition.Value, Allocator.Temp);
            AnimationStream reference = AnimationStream.Create(ref m_RigDefinition.Value, Allocator.Temp);
            poseSampler.Sample(ref pose, new DiscreteTime(0f));
            referenceSampler.Sample(ref reference, new DiscreteTime(0f));
            referenceSampler.Dispose();
            poseSampler.Dispose();

            // Delta writes reference^-1 * pose to the additive stream. Applied to the reference pose, it gives the pose
            // back. The poses don't change, so compute the additive pose once and keep its buffer. A stream can't be a
            // field, so create a view of the buffer when you need the stream.
            m_Additive = new NativeArray<AnimatedData>(m_RigDefinition.Value.Bindings.StreamSize, Allocator.Persistent);
            AnimationStream additive = AnimationStream.Create(ref m_RigDefinition.Value, m_Additive);
            additive.Delta(pose, reference);
            reference.Dispose();
            pose.Dispose();

            // The bones that the mask doesn't list get a weight of 0, so only the bones below the mask root get the
            // additive pose. Because propagateWeight is true, the weight of the mask root also applies to its children.
            using WeightMaskBuilder maskBuilder = new WeightMaskBuilder(
                Allocator.Temp, defaultTransformWeight: 0f, defaultGenericWeight: 1f);
            maskBuilder.SetTransformMask(new StringHash(maskRootPath), 1f, propagateWeight: true);
            m_WeightMask = maskBuilder.ToWeightMask();
            m_WeightMaskSampler = m_WeightMask.Value.ToWeightMaskSampler(ref m_RigDefinition.Value, Allocator.Persistent);
            m_Time = 0f;
        }

        void OnDisable()
        {
            // Dispose the samplers and the buffer before the rig definition that they use.
            if (m_BaseSampler.IsCreated)
                m_BaseSampler.Dispose();
            if (m_Additive.IsCreated)
                m_Additive.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 the base clip at a time, adds the weighted pose difference, and writes the pose to the transforms.
        public void ApplyPose(float time)
        {
            if (!m_Additive.IsCreated)
                return;

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

            // The weight of each channel is poseWeight multiplied by its weight in the mask. Weight scales the additive
            // values towards zero and the rotations towards the identity rotation, for each channel. Use it on an
            // additive stream only: on a pose, it would also scale the bone lengths and scales.
            AnimationStreamMask mask = AnimationStreamMask.CreateReadOnly(ref m_RigDefinition.Value, m_WeightMaskSampler);
            AnimationStream weighted = AnimationStream.Create(ref m_RigDefinition.Value, Allocator.Temp);
            AnimationStream additive = AnimationStream.Create(ref m_RigDefinition.Value, m_Additive);
            weighted.Weight(additive, poseWeight, mask);

            // Add applies the weighted additive pose to the output pose. To blend several additive layers, weight each
            // one, then add them in turn.
            output.Add(weighted);

            // 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.
            weighted.Dispose();
            output.Dispose();
        }
    }
}
```

## Weight(AnimationStream, AnimationStream, float, AnimationStreamMask)

Weights the input stream using a stream weight mask and stores the result in the stream.

```csharp
public static void Weight(this ref AnimationStream stream, in AnimationStream input, float weight, in AnimationStreamMask mask)
```

### Parameters

**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The stream that receives the result. The method overwrites its previous contents.**** (\[AnimationStream]\(/engine/7000.0/script-reference/unity/animations/animationstream)): The stream to weight.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The weight to apply to the stream. The mask scales it for each channel.**** (\[AnimationStreamMask]\(/engine/7000.0/script-reference/unity/animations/animationstreammask)): The mask that scales the weight of each channel.
