---
title: Core.AimConstraintData
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/core/aimconstraintdata
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata.md
last_updated: 2026-11-30
generated_at: 2026-11-30T20:51:08.533Z
locale: en-us
---

# Core.AimConstraintData

> AimConstraint solver settings.

## 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 struct Core.AimConstraintData
```

## Remarks

[Core.AimConstraintData.LocalAxesMask](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/localaxesmask.md) selects the axes of the constrained bone, in the space of its parent, around which the constraint can rotate it. For example, a mask of (false, true, false) only turns the bone around its y-axis. [Core.AimConstraintData.RootUpAxis](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/rootupaxis.md) keeps [Core.AimConstraintData.UpAxis](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/upaxis.md) as close as possible to an up direction in character space, so the bone doesn't roll around its aim axis.

The solver adds the rotations towards the sources by their weights. If the weights add up to more than 1, it divides them by their sum. If they add up to less than 1, the bone only turns part of the way.

The following example is a `MonoBehaviour` that makes the chest and the head of a character look at weighted points of interest.

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 Unity.Mathematics;
using UnityEngine;

namespace Unity.Animations.DocumentationExamples
{
    // This example plays an idle clip and makes the character look at points of interest, such as the player and a
    // nearby door. The chest turns a little towards them, and the head aims at them. Assign a clip that animates the
    // transforms under the GameObject of this component, with paths relative to this GameObject, including the chest
    // and the head. Then assign the skeleton root, the top bone of the skeleton, a direct child of this GameObject.
    // Assign the chest, the head, the points of interest, and the weight of each point.
    //
    // A point with twice the weight of another pulls the gaze twice as much. When the weights add up to less than 1,
    // the gaze only turns part of the way. In the default pose of the rig, the z-axis of the chest and of the head
    // points forward and their y-axis points up.
    public class AimConstraintExample : MonoBehaviour
    {
        public AnimationClip clip;
        public Transform skeletonRootTransform;
        public Transform chest;
        public Transform head;
        public Transform[] pointsOfInterest;
        public float[] interestWeights;

        BlobObjectReference<RigDefinition> m_RigDefinition;
        NativeArray<TransformHandle> m_BoneTransforms;
        ClipSampler m_Sampler;
        int m_ChestIndex;
        int m_HeadIndex;
        NativeArray<float3> m_Positions;
        NativeArray<float> m_Weights;
        NativeArray<quaternion> m_NoOffsets;
        float m_Time;

        void OnEnable()
        {
            if (clip == null || skeletonRootTransform == null || pointsOfInterest == null || interestWeights == null
                || pointsOfInterest.Length != interestWeights.Length)
                return;

            // The reference keeps the rig definition alive until you dispose it.
            using RigBuilder rigBuilder = RigBuilder.Create(
                transform, skeletonRootTransform, new[] { clip }, Allocator.Temp);
            m_RigDefinition = rigBuilder.ToRigDefinition();
            RigDefinitionUtility.BindTransforms(
                ref m_RigDefinition.Value, transform, Allocator.Persistent, out m_BoneTransforms);
            m_Sampler = clip.ToClipSampler(ref m_RigDefinition.Value, Allocator.Persistent);
            m_Time = 0f;

            // Find the bones once. A transform that isn't a bone of the rig has the index -1, so check that the clip
            // animates the chest and the head.
            m_ChestIndex = FindBoneIndex(chest);
            m_HeadIndex = FindBoneIndex(head);
            if (m_ChestIndex < 0 || m_HeadIndex < 0)
                return;

            m_Positions = new NativeArray<float3>(pointsOfInterest.Length, Allocator.Persistent);
            m_Weights = new NativeArray<float>(interestWeights, Allocator.Persistent);

            // Each source has a rotation offset, applied after the rotation that aims at it. These sources have none.
            m_NoOffsets = new NativeArray<quaternion>(pointsOfInterest.Length, Allocator.Persistent);
            for (int i = 0; i < m_NoOffsets.Length; ++i)
                m_NoOffsets[i] = quaternion.identity;
        }

        void OnDisable()
        {
            if (m_Positions.IsCreated)
                m_Positions.Dispose();
            if (m_Weights.IsCreated)
                m_Weights.Dispose();
            if (m_NoOffsets.IsCreated)
                m_NoOffsets.Dispose();

            // Dispose the sampler before the rig definition that it uses.
            if (m_Sampler.IsCreated)
                m_Sampler.Dispose();
            if (m_BoneTransforms.IsCreated)
                m_BoneTransforms.Dispose();
            m_RigDefinition.Dispose();
        }

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

        // Samples the clip at a time, aims the chest and the head at the points of interest, and writes the pose to
        // the transforms.
        public void ApplyPose(float time)
        {
            if (!m_Positions.IsCreated)
                return;

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

            // The points are in character space. Convert them from world space, so that the character looks at the
            // points wherever it stands and however it turns.
            for (int i = 0; i < m_Positions.Length; ++i)
                m_Positions[i] = transform.InverseTransformPoint(pointsOfInterest[i].position);

            // The chest only turns around its y-axis. The mask selects the axes of the bone, in the space of its
            // parent, around which the constraint can rotate it. A weight of 0.3 turns it a third of the way.
            Core.AimConstraintData chestAim = Core.AimConstraintData.Default();
            chestAim.Index = m_ChestIndex;
            chestAim.AimAxis = new float3(0f, 0f, 1f);
            chestAim.LocalAxesMask = new bool3(false, true, false);
            chestAim.SourcePositions = m_Positions;
            chestAim.SourceWeights = m_Weights;
            chestAim.SourceOffsets = m_NoOffsets;
            Core.SolveAimConstraint(ref stream, chestAim, 0.3f);

            // Solve the head after the chest, because the head aims from where the chest puts it. RootUpAxis keeps the
            // y-axis of the head as close as possible to the up axis of the character, so the head doesn't tilt to the
            // side when it looks up or down.
            Core.AimConstraintData headAim = Core.AimConstraintData.Default();
            headAim.Index = m_HeadIndex;
            headAim.AimAxis = new float3(0f, 0f, 1f);
            headAim.UpAxis = new float3(0f, 1f, 0f);
            headAim.RootUpAxis = new float3(0f, 1f, 0f);
            headAim.SourcePositions = m_Positions;
            headAim.SourceWeights = m_Weights;
            headAim.SourceOffsets = m_NoOffsets;
            Core.SolveAimConstraint(ref stream, headAim, 1f);

            // 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(stream, m_BoneTransforms);

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

        // Returns the bone index of a transform, or -1 if no bone has the transform.
        int FindBoneIndex(Transform bone)
        {
            if (bone == null)
                return -1;
            for (int i = 0; i < m_BoneTransforms.Length; ++i)
            {
                if (m_BoneTransforms[i] == bone.transformHandle)
                    return i;
            }
            return -1;
        }
    }
}
```

## Fields

| Value                                                                                                         | Description                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AimAxis](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/aimaxis.md)                 | Specifies the aim axis of the constrained bone to use in order to orient its forward direction to the source positions.                                                                                                    |
| [Index](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/index.md)                     | The constrained bone index.                                                                                                                                                                                                |
| [LocalAxesMask](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/localaxesmask.md)     | Specifies the axes to which the constraint can apply rotation.                                                                                                                                                             |
| [LocalOffset](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/localoffset.md)         | Specifies an additional local space rotation offset to apply to the constrained bone, after it has been rotated toward its target.                                                                                         |
| [RootUpAxis](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/rootupaxis.md)           | Up axis in character space. The constraint will try to keep the RootUpAxis and the UpAxis aligned. Note that this axis can be zero, in this case no effort is made to keep the up axis aligned.                            |
| [SourceOffsets](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/sourceoffsets.md)     | The rotation offset for each source, in the parent space of the constrained bone. The solver applies each offset after the rotation that aims the bone at that source.                                                     |
| [SourcePositions](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/sourcepositions.md) | The list of source positions that influence the constrained bone's orientation. The constraint calculates rotation toward each target to produce a weighted sum. The order of source positions does not affect the result. |
| [SourceWeights](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/sourceweights.md)     | The list of weights each source contributes to the final constrained pose.                                                                                                                                                 |
| [UpAxis](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/upaxis.md)                   | Up axis of the constrained bone, in local space.                                                                                                                                                                           |

## Static Methods

| Method                                                                                        | Description                                                    |
| --------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [Default](/engine/7000.0/script-reference/unity/animations/core/aimconstraintdata/default.md) | Returns a set of default values for the aim constraint solver. |
