Quick question about RPCs

If I did something like this

            if ( Vector3.Distance(transform.position, obj.transform.position) > activateDistance )
            {
                head = obj;
                photonView.RPC("EnableEnemy", RpcTarget.AllBuffered);
            }  
[PunRPC]
    void EnableEnemy()
    { 
        target = head.transform;
        activated = true;
    }

which of these scenarios would happen?

1.
The function runs on all clients, with the same head object for each client, making the head variable the same across the server
2.
The function runs on all clients, but the head variable is different for each client, making the enemy target different players since the head variable is different for each client

Basically I want to know if I run an RPC, will it run with the same info for everyone?

Variables can be different on clients. If you want to be sure that the variables are the same you have to pass them via parameter into the RPC function. Note that in your example with a transform, transforms are not supported since they can't be serialized over the network. But you can send a PhotonView in case the object has one.

1 Like