How do I sync items in an array in a multiplayer game?

Godot Version

4.6

Question

For example, I have an array that has different items in it, and the game randomly chooses one item and deletes the other items. How do I sync this so everyone gets the same item and not a different one?

Have the server pick the item and RPC everyone, or use a seeded random that always returns the same everywhere (sync the seed right before). First approach is probably more secure.

2 Likes

How exactly do I do that? Right now I’m researching how to use RPC, but it would be helpful if you could explain it.

OK, an RPC is a Remote Procedure Call, or a function (procedure) that everyone knows and can be called remotely. Basically, if all clients have a list of items, the server can pick a number (lets say 5), and pass that as an argument into the function. Everyone will get that function pick_item(5) and choose the 5th item from their list, making it synced. I’m bad at explaining, so for more info, check the docs: High-level multiplayer — Godot Engine (stable) documentation in English MultiplayerAPI — Godot Engine (stable) documentation in English

1 Like