Understanding Remote Procedure Calls

Hey Guys

I’ve submerged myself in the Unity Networking documentation, but I’m a little lost on exactly how RPCs work.

I understand I can Implement them like so:

[RequireComponent (typeof(NetworkView))]
public class NetworkedClass : MonoBehaviour
{
    private string test = "";
    
    protected void Start()
    {
        this.networkView.RPC("doSomething", RPCMode.Others);
    }

    [RPC]
    private void doSomething()
    {
        this.test = "derp";
    }

}

Now, I would assume that Unity is doing something behind the scenes to make a static version of my “doSomething” method. I also assume that this static method is agnostic to it’s class.

This means that in my example, an instance of NetworkedClass would never get the test string value set. Is this correct?

My intention is to use RPCs to send information between client and server objects, since the data doesn’t update frequently enough to require constant synchronization. As RPCs seem to be limited to global static methods, I feel like I need to write a bunch of code that handles passing the result of an RPC to the intended object.

Can anyone explain this to me?

Thanks,

Ves

EDIT: I had the audacity to answer before making sure I was completely up-to-date with the doc!

ORIGINAL:

Forgive me if I have misunderstood your exact concern.

Remote Procedure Calls gives your the ability to call some function in another process B and get the return value back to you in a synchronously way, whether this process B is yourself, someone else in your program or around the world, doesn’t matter.

Usually a RPC-function can have any functionality, side-effects or any return value, ie. no different from any other function, except it can also be called by someone else than your-self (as a process). Also meaning that to receive the “derp” string or the content of this.test, you simply return it.

As I haven’t tried it, I cannot say if your instance of NetworkedClass will be able to see the assignment of ‘test’ after the RPC call, but the correct way, is to let the RPC-function doSometing() return the value instead. As simply as that.