When I call rigBuilder.Build()
in my script it converts all rig weights in the scene to zero.
But when I call it like rigBuilder.Invoke("Build", 0.01f)
it works without affecting the rest of the weights of the rig. I used to call it like this in the past, but I can't do that anymore because I added some things to the script to solve other problems, and when calling it like this, Unity crashes.
This is my script:
public void EquipOrPutAway(Gun gun)
{
if (CanEquipOrPutGunAway())
{
if (hasGun())
{
if (gun != activeGun)
{
WantAnotherGun = true;
SelectedGun = gun;
}
isEquippingOrChangingGun = true;
IsHolsterIn = true;
activeGun.audioSource.PlayOneShot(activeGun.HolsterInClip);
activeGun.audioSource.minDistance = activeGun.MinSoundDistance;
activeGun.audioSource.maxDistance = activeGun.MaxSoundDistance;
animator.SetTrigger("Holster Gun In");
}
else
{
isEquippingOrChangingGun = true;
IsHolsterOut = true;
animator.runtimeAnimatorController = gun.TPSGunController;
rightIKGun.data.target = gun.holsterTarget.transform;
rightIKGunHint.localPosition = gun.RightIKGunHintPosition;
leftIKGun.data.target = gun.leftIKGunTarget.transform;
leftIKMagGun.data.target = gun.gunIKMagTarget.transform;
leftIKBoltGun.data.target = gun.gunIKBoltTarget.transform;
magMultiParentConstraint.data.constrainedObject = gun.Mag.transform;
magMultiParentTarget.SetParent(gun.magMultiParentTarget.transform);
magMultiParentTarget.localPosition = Vector3.zero;
magMultiParentTarget.localRotation = Quaternion.identity;
animator.UnbindAllStreamHandles();
animator.UnbindAllSceneHandles();
rigBuilder.Build();
animator.Rebind();
SelectedGun = gun;
animator.SetTrigger("Holster Gun Out");
}
}
}