Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Quick question about RPCs

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

  1. jlorenzi

    jlorenzi

    Joined:
    May 2, 2021
    Posts:
    290
    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?

    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?
     
  2. Lukeesta

    Lukeesta

    Joined:
    Jan 7, 2016
    Posts:
    78
    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.