# ConstraintSource

> Represents a weighted position that can be used in a constraint.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.Animations](/engine/6000.5/script-reference/unityengine/animations.md)
* **Assembly:** UnityEngine.AnimationModule

```csharp
public struct ConstraintSource
```

## Remarks

Use this struct to provide a weighted position to a constraint that implements the [IConstraint](/engine/6000.5/script-reference/unityengine/animations/iconstraint.md) interface. You can use many constraint sources in a constraint. To adjust the effect these sources have on the constraint, set the [weight](/engine/6000.5/script-reference/unityengine/animations/constraintsource/weight.md) parameter.

Additional Resources: [IConstraint](/engine/6000.5/script-reference/unityengine/animations/iconstraint.md) [PositionConstraint](/engine/6000.5/script-reference/unityengine/animations/positionconstraint.md) [RotationConstraint](/engine/6000.5/script-reference/unityengine/animations/rotationconstraint.md) [ScaleConstraint](/engine/6000.5/script-reference/unityengine/animations/scaleconstraint.md) [AimConstraint](/engine/6000.5/script-reference/unityengine/animations/aimconstraint.md) [ParentConstraint](/engine/6000.5/script-reference/unityengine/animations/parentconstraint.md)

## Examples

```csharp
using UnityEngine;
using UnityEngine.Animations;

// The example creates a new MonoBehaviour that is used alongside a ParentConstraint component.
// At runtime, the component adds two sources to the parent constraint and uses the property
// 'switchSource' to dynamically switch from one to the other.
[RequireComponent(typeof(ParentConstraint))]
public class ConstraintSourceSwitcher : MonoBehaviour
{
    private ParentConstraint m_ParentConstraint;

    public Transform source1;
    public Transform source2;

    public bool switchSource;

    void OnEnable()
    {
        m_ParentConstraint = GetComponent<ParentConstraint>();
        m_ParentConstraint.AddSource(new ConstraintSource { sourceTransform = source1});
        m_ParentConstraint.AddSource(new ConstraintSource { sourceTransform = source2});
    }

    public void Update()
    {
        m_ParentConstraint.SetSource(0, new ConstraintSource
        {
            sourceTransform = source1,
            weight = switchSource ? 0f : 1f
        });
        m_ParentConstraint.SetSource(1, new ConstraintSource
        {
            sourceTransform = source2,
            weight = switchSource ? 1f : 0f
        });
    }
}
```

## Properties

| Property                                                                                                      | Description                                                   |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| [sourceTransform](/engine/6000.5/script-reference/unityengine/animations/constraintsource/sourcetransform.md) | The transform component of the source object.                 |
| [weight](/engine/6000.5/script-reference/unityengine/animations/constraintsource/weight.md)                   | The weight of the source in the evaluation of the constraint. |
