Synchronize activation/deactivation from non network game objects

Hey, I’m trying to create a multiplayer shooter and I have multiple weapons on my weapon bone but deaktivated. When I switch my weapon, only the player itself can see the ne weapon but not other clients. So how can I sync the activation and deactivation from game objects, that don’t have a network object component? Can someone help me pls? i already try this:

[Rpc(SendTo.Server)]
public void RequestWeaponChangeServerRpc(int _previousWeaponIndex2, ulong sourceNetworkOjectId)
 {

    _instantiatedWeapons[_previousWeaponIndex2].gameObject.SetActive(false);
    GetActiveItem().gameObject.SetActive(true);

    UpdateWeaponClientRpc(_previousWeaponIndex2, sourceNetworkOjectId);
}

[Rpc(SendTo.ClientsAndHost)]
private void UpdateWeaponClientRpc(int _previousWeaponIndex2, ulong sourceNetworkOjectId)
{
    Debug.Log($"[ClientRpc] Weapon changed: {_previousWeaponIndex2} -> {GetActiveItem()}");
    _instantiatedWeapons[_previousWeaponIndex2].gameObject.SetActive(false);
    GetActiveItem().gameObject.SetActive(true);
}


private void EquipWeapon()
{
    if (!IsOwner) return;
    if (_instantiatedWeapons.Count == 0) return;

    _instantiatedWeapons[_previousWeaponIndex].gameObject.SetActive(false);
    GetActiveItem().gameObject.SetActive(true);
    RequestWeaponChangeServerRpc(_previousWeaponIndex, NetworkObjectId);
    GetActiveItem().OnEquip(gameObject);

    _actionState = FPSActionState.None; 
}

Check that your code executes as expected. Perhaps the instantiated weapons or the index is just not correct or refer to the wrong objects. Use the debugger to make sure the code executes properly for each client.

Because from what I can tell here, this should work - provided that the Rpc methods are in a NetworkBehaviour script. If not, you need to route the weapon switching from the root object with the NetworkBehaviour that then also runs the code on the weapon script. Respectively the weapon script could hook into events sent out by the root network script.

The ServerRpc needn’t do the activation since it’s already handled by the ClientRpc (also sent to Host). So you can simplify the ServerRpc to this: