Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

How to reference Rigs and change weight through script.

Discussion in 'Animation' started by LofiSenpaiii, Jan 9, 2022.

  1. LofiSenpaiii

    LofiSenpaiii

    Joined:
    Nov 14, 2021
    Posts:
    4
    Hello,

    I have tried several different ways to try and reference a rig through c# and I just change seem to. Is this possible so I can set rig weight through script?
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    80
    Hi @LofiSenpaiii,

    Yes, it's possible to do that. To expose your rig reference in the inspector, you have to make it public or add [SerializeField] attribute. You should be able to reference a Rig component from your script and then modify its weight property
    https://docs.unity3d.com/Packages/c...1/api/UnityEngine.Animations.Rigging.Rig.html

    Something like this
    Code (CSharp):
    1. public Rig m_Rig;
    2.  
    3. void Update()
    4. {
    5.     var myNewWeigth = Mathf.Abs(Mathf.Sin(Time.time));
    6.     m_Rig.weight = myNewWeight;
    7. }
    Which version of the Animation Package are you using?
     
unityunity