#How does RPC work under the hood?

1 messages · Page 1 of 1 (latest)

heavy meteor
#

I'm an experienced developer who has created a multiplayer game before with ENet, in my own engine.

I want to know more about how @rpc works under the hood.

  • how does the system identify objects across client-server boundary? Is each node given a unique id, shared across client-server?
  • If so, how are these id's set?
  • Is there a way to access these ids?
heavy meteor
#

yo!! :))

finite axle
#

I checked the source, it's done by NodePath. First it checks if every peer has been sent an RPC with that path before, if not then it sends a message like

[path_hash][node_path][rpc_data]

Else it just sends

[path_hash][rpc_data]

There's no way to get this info, the hashtable is maintained automatically.

heavy meteor
#

thank you so much

#

Interesting. So there's an internal map

{
  [node_hash] -> node_path
}

that client and server both keep

#

and on the first packet sent, the path/hash is registered. That's so amazing

#

I built a similar system for my game with ids, but it was all hand-made (and probably buggy 🤣)

#

thanks <3

#

Do you have any tips for diving into the source code? I suspect that I will have questions like this in the future for other things; I'd like to be able to just dive through the godot source

#

Oh wait im silly

#

its the hash -> node-path, other way around

#

woops

finite axle
#

The nodes communicate with "servers" using a handle called an RID. When node properties are changed, they may call like RenderingServer.set_transform(self.rid, self.transform) sort of thing. It's normal for these servers to act like a black box with most actions being sending data into them. Keeps the API surface small.

The nodes usually are found in /scene and the server in /server. Sometimes a server is implemented there too, if not it can be found in /modules or /drivers.

So my search went like
MultiplayerServer -> /servers/multiplayer_server -> /modules/multiplayer/ -> ... -> https://github.com/godotengine/godot/blob/53be3b78d1634406f1fb29e3802c608a5f5104a1/modules/multiplayer/scene_rpc_interface.cpp#L306