Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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:
    162
    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