I’m curious about how the new multiplayer nodes work under the hood, but I’m inexperienced with C++ and am not confident that I understand the source code.
Do the multiplayer nodes differ from using RPCs to spawn nodes and sync properties? If so, how? If not, what kind of RPC setup are these nodes equivalent to?
I took a dig at MultiplayerSynchronizer for fun to see how it works.
The first thing I’ve noticed is that MultiplayerSynchronizer itself actually doesn’t do any synchronization, it just provides data, like what’s changed in get_delta_state.
This is then used by SceneReplicationInterface::_send_delta, which encodes and compresses the properties that have changed. The actual data sending goes through a bunch of steps:
The above then ends up calling the MultiplayerPeer’s put_packet method directly, which depends on which implementation you’ve chosen. Here’s ENetMultiplayerPeer::put_packet for example.
So to conclude, it just creates and sends the packets directly.
I will add that for spawning nodes you would use a MultiplayerSpawner.
Under the hood it listens for added child signals and if the node matches a what is on the configuration list it will send a reliable rpc call to spawn on the remote scenes.
There is some more fancy stuff going on, because if there are lots of developments within the game and a new client joins the MultiplayerSpawner’s will get to work on syncing state for the new client.
I don’t seen any benefits to using rpc over the multipleplayer nodes. But can be useful in other scenarios.
Because if you are writing scripts to mimic native code it will be inherently slower.