Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit) (+2)

Some helpful tips for anyone planning to learn multiplayer in Godot (things that were confusing to me in the beginning as I was learning):

1. There is a Note in the docs with the following statement that is *very* important for those trying to make multiplayer web games: "Most notably, the HTML5 platform currently only offers WebSocket support and lacks some of the higher level features as well as raw access to low-level protocols like TCP and UDP." So, when setting up networked gameplay, do not use NetworkedMultiplayerENet or WebRTCMultiplayer. You must use WebSocketMultiplayerServer/Client/Peer.

2. The high-level multiplayer API ultimately has two kinds of communication. Communication between game instances (effectively from one SceneTree instance to another SceneTree instance - see `MultiplayerAPI.send_bytes`) and communication between nodes executed via `rpc()`/`rpc_id()` calls that target methods to which you have applied the network keywords (`client`, `server`, `sync`, etc.). In the latter case, it's important to note that methods are executed by following the identical absolute NodePath of the executing node. So if /root/A/B calls method `foo()` using RPC, then the remote game instances will also look for a Node at /root/A/B and attempt to call `foo()` on that Node too (to replicate the behavior). So if you want operations to be replicated over the network, then the Node trees have to match. You can't simply target a Node by its reference or its ObjectID because those values are the Node's actual memory address in the computer which will be different between different devices. If you need to relay remote instructions between node trees that are similar, but differently organized, then you'll need to delegate that task either through a Node that *is* shared between the game instances or delegate it to the SceneTree itself (via calling `send_bytes` on one and connecting to the signal that receives those bytes on the other game instance).

Pretty much everything can be learned very readily in the docs/demos and online tutorials, etc. but I just wanted to bring people's attention to this stuff since it can be easy to gloss over it when learning so much new information.

(1 edit)

Re: Your 1st point. Why do you say to not use WebRTC for web games? The official docs suggest the opposite (link):

WebRTC is implemented in Godot via two main classes WebRTCPeerConnection and WebRTCDataChannel, plus the multiplayer API implementation WebRTCMultiplayer. (...) These classes are available automatically in HTML5, but require an external GDNative plugin on native (non-HTML5) platforms.

Oh, that may be the case. Would need to test it. When I made my attempt to do web game stuff, only the ENet and WebSocket stuff existed, and of those two, only WebSocket multiplayer worked with HTML5 builds. WebRTC came on later. I checked back with the docs to see if there was any change, but that quoted line I provided also came from the docs in the high-level multiplayer page, so I thought it was still the case. If the WebRTC docs specify otherwise, then the docs may just need updating to avoid conflicting reports then.