[BossRoom] Why using Messaging instead of RPC ?

Hello,

I have a question about BossRoom.
Unity used the messaging system for ConnectionResult and SceneChanged here : https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/db507ac93b1323d70883dff571c49e8e3fc2eea2/Assets/BossRoom/Scripts/Shared/Net/GameNetPortal.cs#L207

Why not use a RPC to do that ?

I'm new to multiplayer and I was wondering why use one over the other ?

Thanks


General rule of thumb (which sometimes gets ignored then, but in general): if you are initiating a command, then use RPC (you expect some action in return).
If you send notification and stuff, you're messaging (You don't really expect any action in result)

1 Like

Hi Ziboo,

Custom Messages are not bound to any object. RPCs at the moment are bound to a NetworkObject. This means that you must first establish a successful connection with a client before you wish to send RPCs to and from a client. Read more about MLAPI's messaging system here: https://docs-multiplayer.unity3d.com/docs/advanced-topics/messaging-system.

You'll notice here: https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/db507ac93b1323d70883dff571c49e8e3fc2eea2/Assets/BossRoom/Scripts/Server/Net/ServerGameNetPortal.cs#L191, that we want to inform the client of the result of the connection approval. In the case where the connect status is a failure, the only way we are able to communicate with a pending client is through Custom Messages because we don’t have NetworkObjects yet to use RPCs on.

You can consider our usage of Custom Messages as a workaround to this limitation. In the future, we may refactor the connection approval message callback to allow the sending of more contextual connection information.

Hope this clears that up for you.

3 Likes