I read that for many games with a lot of rpc calls it’s wise to set up singleplayer as a fake multiplayer, that said how is singleplayer handled in this situation?
I assume I can just add a OfflineMultiplayerPeer.new() and be done with it, but is there anything I should watch out for?
Use the multiplayer nodes, MultiplayerSpawner and MultiplayerSynchronizer.
In most cases you may not need to write any RPC and just throw a synch’r into your player character scene.
As long as you design your components to have remote state injected into them, while also allowing for local control, then yes.
By default the system starts with an OfflineMultiplayerPeer. You typically override the peer when you setup multiplayer. So you may need to go back to the offline peer when leaving multiplayer.
What I mean by injection is, as an example, if you have Input.is_action_pressed() within your process functions, you cannot inject meaningful input into the remote peers.
Input should set class variables in the _unhandles_input events, that are later used in the process function, which can also be set by the MultiplayerSynchronizer.
Good to know the Offline shouldn’t be a problem! So just reinstate it on server loss/disconnecting got it. I looked into it and it seems not returning to it may be a bug. Can the offline server disconnect at all? I assume not considering it’s nature but assuming is dangerous.
On your other suggestions:
I I do allow a spawner to handle some things, but most of the spawning is done myself since I set stuff on spawn. I thought about the limitation with input you gave and came up with this solution.
On spawn I set recursive multiplayer authority, then set process input/unhandled funcs with is_multiplayer_authority so none of those nodes are listening at all to other players, but still update their position/animation thanks to MultiSynchros. It worked surprisingly well and would be great for physics/process heavy movement etc.
Since my game is a life sim game I don’t really need input/processes on other peers’ characters at all! Interaction between them is handled on the client character’s side.
I don’t think so, I want to say it’s a mostly empty class that makes sure the multiplayer API has something to interact with. Im working on a multiplayer game myself but I haven’t gotten to the disconnect functionality.
MultiplayerSpawner has a custom spawn function that you can pass information to perform a remote spawn procedure.
Also multiplayer spawners can handle nested scenes. So if you compose dynamically the spawner can also handle replicating in that way. A tree of dynamite spawners is also possible.
I took a second pass at them because you recommended them! I had some questions after reading the docs~
I guess the only difference is I would literally be passing it my spawn function as Spawner.spawn(player_data) and removing the add_child line, is it faster or more reliable or something, or just ?
I noticed it specifies “replicates spawns from the authority”? Does that mean the only way to spawn something from a peer is to rpc the server with player_data to then have the server call spawn on the spawner with the data?
How does despawning the nodes it spawns work? Back in the alpha it would freak out when the nodes queue_freed I think so I may have been subconsciously avoiding it (also could be remembering incorrectly).
Generally the answer is yes, the authority of the spawner needs to spawn the node. Although, authority can be delegated just as long as every peer knows who the authority is. (everything defaults to the host/server authority, so… )
The authority of the MultiplayerSpawner watching the despawn-able node needs to remove the node from the tree. (Free, queue_free, remove_child)
I would say the the multiplayer spawner is more geared to a central server auth. But you could just add an RPC function to share the authority. Although I haven’t thought that all the way through.
These nodes are abstracting common RPC tasks that could save you from writing complicated RPC logic. But I would say if you are not doing a central auth architecture things get tricky in general, as p2p is notoriously hard.
I implemented the spawner in my project but in the end pulled an earlier version in favor of keeping my code consistent between spawning & despawning~
I was already setting authority and then the input/process functions manually. I can definitely see where it would be great in many scenarios and I’ll definitely use it in a less complex project!