Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Players Own Animation Rig Weight Does not Update on other players screens

Discussion in 'Netcode for GameObjects' started by XtOxiciTy456, Nov 14, 2023.

  1. XtOxiciTy456

    XtOxiciTy456

    Joined:
    Oct 21, 2021
    Posts:
    2
    Hi there.

    Question about Netcode for Game Objects and animation rigging. I have a Rig with a two bone IK constraint and I want to control it through the weight. I have tried altering this through a network variable and also RPC's

    I also have client network transforms on my characters and other parts.

    Still through these methods the weight/ IK animation only updates on the players character but other characters do not update.

    Would anybody possibly know why?

    Thanks in advance !

    Code (CSharp):
    1.     NetworkVariable<int> IKRigWeight = new(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
    2.  
    3.     void Start()
    4.     {
    5.        
    6.         if (IsOwner)
    7.         {
    8.             animator = GetComponent<Animator>();
    9.  
    10.             IKRigWeight.OnValueChanged += (oldVal, newVal) =>
    11.             {
    12.                 R_HandIK.weight = newVal;
    13.             };
    14.  
    15.        }
    16. }
    17.  
    18.     void Update()
    19.     {
    20.         if (IsOwner)
    21.         {
    22.               if (Input.GetKeyDown(KeyCode.I))
    23.             {
    24.                 IKRigWeight.Value = R_HandIK.weight == 0 ? 1 : 0;
    25.             }
    26.         }
    27. }
     
    Last edited: Nov 14, 2023
  2. XtOxiciTy456

    XtOxiciTy456

    Joined:
    Oct 21, 2021
    Posts:
    2
    Incase anyone else faces this problem I have found the solution through changing the IsOwner Boolean


    Code (CSharp):
    1.     NetworkVariable<int> IKRigWeight = new(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
    2.     void Start()
    3.     {
    4.      
    5.             IKRigWeight.OnValueChanged += (oldVal, newVal) =>
    6.             {
    7.                 R_HandIK.weight = newVal;
    8.             };
    9.             if (!IsOwner) return;
    10.        
    11.             animator = GetComponent<Animator>();        
    12.    }
    13.     void Update()
    14.     {
    15.         if (!IsOwner) return;
    16.      
    17.         if (Input.GetKeyDown(KeyCode.I))
    18.         {
    19.             IKRigWeight.Value = R_HandIK.weight == 0 ? 1 : 0;
    20.         }
    21.     }
    22. }
     
    jackliamkwiecien likes this.