Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved RigBuilder sync problem

Discussion in 'Netcode for GameObjects' started by XperienceGame, Mar 6, 2023.

  1. XperienceGame

    XperienceGame

    Joined:
    Apr 16, 2013
    Posts:
    6
    Hello there,

    I've a little problem. I've a "player prefab" with "NetworkObject", "Client Network Transform" for sync position and rotation. This player prefab have a script for mouvements based on "Character Controller", with new Input System. In all that, work fine like a charm. I've created a RigBuilder for good and more naturaly aiming (with raycast system). In multiplayer, all player in scene "online" work fine.

    My problem : I've an animation for "reloading" weapon, but this animation doesn't work with RigBuilder (it's logic with rig configuration constraint for all bones in animation), my solution => desactivate RigBuilder component, or layer, or weight of Rig object when animation's call. It's work in Local player view, but not at all in other player view. In other player view character don't really move, he has a suttering's like, weird movement in animation time. The RigBuilder or "rig weight" or layer has no reaction in other player screen, it's more visible in Editor when other player connected with Build or other editor session. Other player's component no react if it's not a "localPlayer"

    I've tested everything : classical scripting in Update function (don't work), ServerRpc and ClientRpc for sync (don't work all player have animation in one player session view not others), and with condition "IsLocalPlayer" in ClientRpc, don't work too, it's same thing "classic Update" function. I'm lost :/

    PS : after call many times "reload" and rigbuilder enable/disable, the "aiming time" in "constraint aim" is divided by 2, you're in slowmotion rotation.
     
  2. XperienceGame

    XperienceGame

    Joined:
    Apr 16, 2013
    Posts:
    6
    I've resolve my problem : with a second script in "Rig Object", this script control weight in update function, and my player script control the weight with the reload bool.

    exemple in player script :
    Code (CSharp):
    1. [SerializeField] private RigController rigObject;
    2. [SerializeField] private float newValue;
    3.  
    4. private void Update()
    5. {
    6.        if(reload)
    7.        {
    8.             rigObject.newValue = 0f;
    9.            //Animation bool true
    10.        }    
    11.        else if(!reload)
    12.        {
    13.             rigObject.newValue = 1f;
    14.             //Animation bool false
    15.        }
    16. }
    the RigControllerScript :

    Code (CSharp):
    1.  
    2. public class RigController : MonoBehaviour
    3. {
    4.     [SerializeField] public float newValue;
    5.  
    6.     private void Update()
    7.     {
    8.         this.GetComponent<Rig>().weight = newValue;
    9.     }
    10. }
    11.  
    Work fine, after link this "RigController" script in player script. Note : The Rig Object, with this simple script, is a child of "Root" object in player character. =D
     
    Last edited: Mar 6, 2023