We have been really busy working on the foundation of the networking and multiplayer classes lately, and there are quite a few new features to talk ab

Multiplayer in Godot 4.0: RPC syntax, channels, ordering

submited by
Style Pass
2021-09-25 16:00:07

We have been really busy working on the foundation of the networking and multiplayer classes lately, and there are quite a few new features to talk about. In this post, we'll start by showing some of the new RPC syntax and features.

The master keyword would mean that a function could be called on the "network master", while puppet that a function could be called only on the "non-master" peers. Additionally, the old master keyword had very little usage, since remote could be used in its place with little to no effort.

By default, @rpc only allows calls from the multiplayer authority, which is the server by default. You can optionally set the multiplayer authority on a per-node basis via the Node.set_multiplayer_authority() method.

As mentioned above, the @rpc annotation can also take optional parameters. If one of those parameters is any, the RPC will be callable by any connected peer, behaving like the old remote keyword. You can get the ID of the peer that is making the call via the MultiplayerAPI.get_remote_sender_id() method.

There is no direct replacement for the rarely used master keyword. In those cases, @rpc(any) can be used by adding an extra check against the called ID as is done above.

Leave a Comment