Synchronizing game object across clients

Is it possible to have a pre-existing gameobject, that is controlled via script, and synchronize its position and rotation for all clients. If yes, then how can I do it?

I’d like to have an object that already exists in the scene (I can’t spawn it, it has to be an already existing in the scene game object), control its position and rotation via script on the server and have all the clients see the change in its position and rotation. How can I achieve that?

Good day.

I think you need to watch some basic tutorials about networking and multiplayer. You are asking one of the basics… Spend 3-4 hours with some “boring but important” tutorial before commence, it will help you a lot!

PD: The easy solution is make the server to move the object and transmit the position to clients. IT’s a component called Network Transform.

PD2: Spawn an object in the network is not the same as instantiate, In this context, spawn means something like “make everybody aware that this is a object in the network”.

Good Luck!

Bye!

Ok, so I approached the problem differently. Instead of using Network Transform I wrote my own script.
Firstly, I wrote a short script to disable on all clients the component moving the object. Then, I wrote the script to send position and rotation from server to clients:

public class NetworkShareTransformData : NetworkBehaviour
{
    [SyncVar] public Vector3 currentPosition = Vector3.zero;
    [SyncVar] public Quaternion currentRotation = Quaternion.identity;

    [ClientRpc]
    private void RpcSyncPositionWithClients(Vector3 positionToSync)
    {
        currentPosition = positionToSync;
    }

    [ClientRpc]
    private void RpcSyncRotationWithClients(Quaternion rotationToSync)
    {
        currentRotation = rotationToSync;
    }

    private void Update ()
    {
        if (isServer)
        {
            RpcSyncPositionWithClients(this.transform.position);
            RpcSyncRotationWithClients(this.transform.rotation);
        }
    }

    private void LateUpdate()
    {
        if (!isServer)
        {
            this.transform.position = currentPosition;
            this.transform.rotation = currentRotation;
        }
    }
}