Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Resolved Quick question about RPCs

Discussion in 'Multiplayer' started by jlorenzi, Jun 6, 2023.

  1. jlorenzi


    May 2, 2021
    If I did something like this
    Code (CSharp):
    1.             if ( Vector3.Distance(transform.position, obj.transform.position) > activateDistance )
    2.             {
    3.                 head = obj;
    4.                 photonView.RPC("EnableEnemy", RpcTarget.AllBuffered);
    5.             }  
    6. [PunRPC]
    7.     void EnableEnemy()
    8.     {
    9.         target = head.transform;
    10.         activated = true;
    11.     }
    which of these scenarios would happen?

    The function runs on all clients, with the same head object for each client, making the head variable the same across the server
    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?
  2. Lukeesta


    Jan 7, 2016
    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.
    jlorenzi likes this.