0
\$\begingroup\$

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");

        }
    }
}
New contributor
Ahmed Dyaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
4
  • \$\begingroup\$ If Unity is crashing, that's a sign of a much deeper problem you should solve first, as the roots of that problem could have side effects that make other things behave badly (like getting all zero weights) \$\endgroup\$
    – DMGregory
    May 21 at 16:45
  • \$\begingroup\$ What I added is : animator.UnbindAllStreamHandles(); animator.UnbindAllSceneHandles(); to solve this problem : gamedev.stackexchange.com/questions/205673/… \$\endgroup\$
    – Ahmed Dyaa
    May 22 at 11:50
  • \$\begingroup\$ If that solved the problem, it should be posted as an Answer below. If not, then you should edit your question to include this information and clarify how it fits into the current problem. \$\endgroup\$
    – DMGregory
    May 22 at 13:48
  • \$\begingroup\$ I read on the Unity forum that this solves the problem whose link I sent above, but I did not know if it was solved or not because of rigBuilder.Build(); bug for which I posted the question \$\endgroup\$
    – Ahmed Dyaa
    May 22 at 14:38

0

You must log in to answer this question.

Browse other questions tagged .