Search Unity

Cannot set weight of individual sources in Position Constraint

Discussion in 'Animation' started by sacb0y, Feb 15, 2020.

  1. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    202
  2. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    202
  3. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    202
    Actually no I can't get this to work at all :(

    I tried making a helper for bolt, but I can't get the values to change. Attaching script to respective objects.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Animations;
    5.  
    6. public class ConstraintHelper : MonoBehaviour
    7. {
    8.     private PositionConstraint positionConstraint;
    9.     private RotationConstraint rotationConstraint;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         positionConstraint = gameObject.GetComponent<PositionConstraint>();
    15.         rotationConstraint = gameObject.GetComponent<RotationConstraint>();
    16.     }
    17.  
    18.     public void PositionSourcesWeight(float newWeight, int sourceIndex)
    19.     {
    20.         ConstraintSource source;
    21.         source = positionConstraint.GetSource(sourceIndex);
    22.         source.weight = newWeight;
    23.     }
    24.  
    25.     public void RotationSourcesWeight(float newWeight, int sourceIndex)
    26.     {
    27.         ConstraintSource source;
    28.         source = rotationConstraint.GetSource(sourceIndex);
    29.         source.weight = newWeight;
    30.     }
    31. }
    What am I doing wrong?

    The weight values refuse to change.
     
unityunity