Distribute the message to all clients except the sender

How to share the coordinates of an object moved using NetCode with all clients using RPC?

The gameObject attached with NetworkTransfer and NetworkObject components.

void FixedUpdate()
    {
        if (IsClient)
        {
            sendMsgClientRpc(this.transform.position, this.transform.rotation);
        }
    }


    [ServerRpc(RequireOwnership = false)]
    void sendToServerRpc(Vector3 pos, Quaternion rot, ServerRpcParams serverRpcParams = default)
    {

        GetComponent<Transform>().position = pos;
        GetComponent<Transform>().rotation = rot;

    }
  1. Client 1 moves the object.
  2. ServerRPC receives the coordinates.
  3. All clients’ gameObjects are moved.

In this way, the gameObject of Client1 (sende) is called again and a message is sent to ServerRPC.

Thus, congestion occurs between ServerRpc and Client1.


Is it better not to use RPC in this method?
Is there any other optimal way?

Isn’t the network transform component supposed to handle this?
You can send a clientRPC to update the position of the object for each client and use RPC params to decide which clients gets the message.

Isn’t ClientRPC only called from the Server?
Are there Client-to-Clinet messeaging method?

I tried to find ClientRpc parameter reference, but I can not find.
Would you let me know the URL which is described about ClientRpc parameter.

You can call a ServerRPC that calls ClientRPC

I think that in here: https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/rpc-params/index.html

I changed the code

    void FixedUpdate()
    {
        if (IsClient)
        {
            sendToServerRpc(this.transform.position, this.transform.rotation);
        }
    }


    [ServerRpc(RequireOwnership = false)]
    void sendToServerRpc(Vector3 pos, Quaternion rot, ServerRpcParams serverRpcParams = default)
    {
        sendMsgClientRpc(pos, rot);
    }

    [ClientRpc]
    void sendMsgClientRpc(Vector3 pos, Quaternion rot, ClientRpcParams clientRpcParans = default)
    {
        GetComponent<Transform>().position = pos;
        GetComponent<Transform>().rotation = rot;
    }

Indeed, I could call ClinetRPC from ServerRPC.
However, changing the position of an object in a Client does not change the position of objects in other Clients.

Is the Network Trasfer component affecting this?

void sendMsgClientRpc(Vector3 pos, Quaternion rot, ClientRpcParams clientRpcParans = default)

In the above declaration, clientRpcParans seems to have only dedault.

The inability to change the position of an object only from the Server may be a basic design error.

Is there a sample that allows the object to be repositioned from the Client?

You shouldn’t change the position of an object like that. If you want to change it’s position you need to do it fro mthe server, doing it from the clients will be possible only if the object is local and that’s not a good solution. You should probaly get back to your first code. I can’t think of a goos way to stop the server from sending the position to the client again.

Thanks IavagoatGG:)

they added
[Rpc(SendTo.Everyone)]
just update to 1.8.1