Search code examples
c#unity-game-enginenetwork-programmingmethodsrpc

Mlapi RPC Attributes


I was following the tutorial about 'Mlapi' in Unity. In the tutorial, I have a question when I studying about RPCs.

So the question I have is

  1. When I make a method with the ServerRpc attribute how does the 'Mlapi' handle that method? According to 'Mlapi' documentation, All I have to do to call the ServerRpc function is just making a direct function call with parameters. But what happens when I call the method marked by ServerRpc? What I did was just calling the method marked by the ServerRpc attribute. But how the 'Mlapi' get method marked by the ServerRpc attribute or other Rpc attribute I wrote? And how does the 'Mlapi' call the method from the client and execute it on another machine?

Solution

  • RPC is a well-documented concept. You should look up some references. The RPC client "marshals" your parameters into a format that can be transmitted via network, and sends them with information that tells the other side which function you are calling. The RPC server on the other end "unmarshals" those parameters back into binary structures and calls the function. It then "marshals" the return value and ships it back to the client, where it gets "unmarshalled" back to you.

    The RPC server knows which services it is offering, so it's not just calling random functions.