Instantiate multiplayer object with custom data?

Godot Version

4.3

Question

In a networked game using the high level multiplayer API, are there any tricks for instantiating an object with custom data? I am finding that nothing set by my server gets replicated to my client for objects where the client is the network authority over that client. I’m even struggling to get an RPC function to be called on the client object instance when calling the RPC function directly after instantiation.

In my case I have MultiplayerSpawner in my game scene and when I instantiate a player instance this instance is replicated across clients. For each client I am trying to set a client_id value for each player instance so I can determine if the camera and UI elements need to be active. But this problem also applies to the players position which also can’t be set by my server, presumably because the server is not the network authority over the client.

Any ideas?

Using the custom spawn function of a MultiplayerSpawner, nested spawners, synchronized player preferences.

Spawn function can send a data with instructions to construct a player.

Nested spawners can work with composed players, this requires some “snapping” behavior when child is added to player, (oh a weapon has been added? lets set it to the players hand).

The last being a client authed profile of settings the player has chosen, that are sent to the server so the server can create the client properly. (The profile is actually shared with all peers, with each peer having their own synched profile). This would also help the custom spawn function approach. But since the client also has the same profile you may not need to custom spawn. You should really consider doing this anyway as it can be used to store color choices and client names that can be used for game stats and other UI stuff.

This can all be done without any RPCs

The last part is make a central authority network architecture. The clients only send input data to the server, the server moves the player and sends back position and what not. Everything is authed to the server except the client input syncher.(This requires you to design player character and input separately so the input data can easily be passed to the server and utilized by the player character). To help with responsiveness you can do some client side prediction by allowing the input to be used locally on the client too.

If you want a peer-to-peer experience, the custom spawn can help with initial state.

1 Like