Changing the Rig weight from a script

Hello everybody,

I’m working on an animation that can use the normal animator and use the rig functionality from the Unity Animation Rigging package.
I’m trying to edit the weight slider from a script so I can blend between normal animation and rigged animation.
I can drag the weight slider in the Inspector but haven’t been able to edit the slider in a C# script.

My question is: How can I edit the weight slider with a C# script.

To make everything a bit more clear: Brackeys talks about the weight slider in this video:

(@ 8:04)

Help is much appreciated!

=========

Fixed it, so if somebody crosses this on google this is the solution:

Add

using UnityEngine.Animations.Rigging;

To the top, afterwards you can reference the rig with public Rig!

4 Likes

Thx. Saved me a lot of time. Well, did cost me some time too :slight_smile:

Thank you very much !!

But how can you change it smoothly?
I have done this but even if I change from 1 to 0 inside a Coroutine decreasing the value every 0.1 seconds, its noticeable and not smoothly.

What does your code look like? I was able to smoothly transition between rig weights using the coroutine below.

IEnumerator SmoothRig(float start, float end)
{
float elapsedTime = 0;
float waitTime = 0.5f;

while (elapsedTime < waitTime)
{
rig.weight = Mathf.Lerp(start, end, (elapsedTime / waitTime));
elapsedTime += Time.deltaTime;

yield return null;
}
}
2 Likes

guys i why can’t i change the value of the weight even if i change its float value

2 Likes

https://discussions.unity.com/t/804724/19

Has this changed? Adding UnityEngine.Animations.Rigging isnt working for me. It says Animations has no Rigging.

3 Likes

If you’re using an Assembly Definition, make sure to add UnityEngine.Animation.Rigging to the list of references:

8110637--1050443--upload_2022-5-7_20-14-12.png

That’s what my problem was.

Note: It shows up as “Unity.Animation.Rigging” without the “s” after “Animation”, but the using statement is still “using UnityEngine.Animations.Rigging;” with the “s”.

I’m on Unity 2020.3.30f1 with “com.unity.animation.rigging”: “1.0.3”

can somebody help me to change the source weight on a script

1 Like