What is the best way to implement interactions in multiplayer

Godot Version

4.5.1

Question

I have been messing around with multiplayer the past few days and got confused with the synchronization part of things.

My game is using a really simple ““host-client”” setup (double quotes cause the player node has full authority, the rest is up to the host to decide gameplay stuff)

Then I got a problem with replicating which player was trying to become the current driver of a car, the variable holding the player value wasnt replicating, after trying a little more I discovered reading the docs that Objects/Resources cant be replicated, neither their ids, just native Variant types or something like that

the image above shows that I could only replicate successfully the peer_id that is trying to become the driver, from that I think that I would probably handle the driver stuff locally (on each client)

but that brings the question, how am I supposed to deal with references in multiplayer games that usually have a lot of interactables like button or boxes that can be grabbed?

These objects are passed by reference, when you do driver = new_player as an example it doesn’t copy the entire new_player Godot only takes new_player’s address in-memory; it’s memory dependent, and your multiplayer peers do not share the same memory, so they cannot point to the same memory address.

That’s the low-level why this happens, usually the fix is to use Node paths if you are trying to replicate nodes. This matches with other multiplayer and RPC stipulations that nodes must match paths on both the client and server.

@export_node_path("Player") var driver: NodePath

If you need to apply this value you can use driver = new_player.get_path(), and to resolve the path any node can use get_node(driver) since get_path() returns a global path.

1 Like

Thanks for the insight gertkeno! that tracks.

The next problem I need to tackle is reparenting (which is also not allowed) but big thanks for now