godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.71k stars 3.03k forks source link

Documentation around multiple custom MultiplayerApi usage is unclear #8771

Open Luminoth opened 7 months ago

Luminoth commented 7 months ago

Tested versions

v4.2.1.stable.mono.official [b09f793f5]

System information

Godot v4.2.1.stable.mono - Pop!_OS 22.04 LTS - X11 - GLES3 (Compatibility) - NVIDIA GeForce RTX 3080 (nvidia; 545.29.06) - AMD Ryzen 7 2700X Eight-Core Processor (16 Threads)

Issue description

Similar to https://github.com/godotengine/godot/issues/87023 I'm unsure if this is a documentation issue, a design issue, or a me issue but after scouring docs and google searches (and an ask on the Godot forums - https://forum.godotengine.org/t/how-are-custom-multiplayerapis-supposed-to-work-with-multiplayerspawner/42335), I can't figure out how to get a custom MultiplayerApi server and custom MultiplayerApi client working in a way that facilitates both Peer-to-Peer (Host Server and Client in a single process with Dedicated Clients connecting to the Host) and Dedicated Servers (Host Server with Dedicated Clients connecting to it).

Based on https://godotengine.org/article/multiplayer-in-godot-4-0-scene-replication/, https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html, and https://forum.godotengine.org/t/how-to-set-a-custom-multiplayer-in-godot-4-0/6957/3 I've come up with https://github.com/Luminoth/Godot-Multiplayer-Demo (sorry about the GameLift code in there, that can be ignored) and it's failing when multiple clients are involved no matter how I run it and no matter how I try and set up the scene tree.

The basic setup is having a /root/ClientManager singleton with a custom MultiplayerApi and a /root/ServerManager singleton with a custom MultiplayerApi (I can't have just a single node for this because it seems you can't have a server peer and a client peer associated with a single MultiplayerApi). My Player has two MultiplayerSynchronizers per the official docs and my Level has a MultiplayerSpawner per the official docs. I've tried spawning the Level and Players below the ServerManager for servers and hosts, and below the ClientManager for clients, but that fails the combined use case because the ClientManager doesn't have a MultiplayerSpawner to synchronize against (and probably shouldn't because that would create duplicate Players for the local client) and spawning the Level below the root, which also fails because the MultiplayerApi's are a part of the manager nodes, causing all of the MultiplayerSpawners and MultiplayerSynchronizes to do nothing. This setup also seems to create a weird need to duplicate RPCs on both the ClientManager and ServerManager nodes for every RPC regardless of who should be handling it (because the RPCs have to exist in both node paths for each end to configure them correctly).

I don't know if it's just me, but I cannot seem to reason out a way to make this work and I haven't seen any examples, official or otherwise, that actually prove out it's even possible despite documentation suggesting that it should be - It is possible to create a new MultiplayerAPI object and assign it to a NodePath in the the scene tree, which will override multiplayer for the node at that path and all of its descendants. **This allows sibling nodes to be configured with different peers, which makes it possible to run a server and a client simultaneously in one instance of Godot.**

Steps to reproduce

This issue is pretty complex in terms of reproduction - essentially what I'm asking for is a working example of a Godot project that can act as a Peer-to-Peer host (client and server in one process) or a dedicated client / dedicated server. I can't say how to replicate doing that tho, if I could then I would just do that thing and the issue would not be here.

Minimal reproduction project (MRP)

Godot-Multiplayer-Demo-main.zip

Not exactly MRP, there's some GameLift stuff in there that isn't relevant to the issue. I can pretty easily, I think, make a new project that guts all of that if it's too much of a hassle.

Luminoth commented 7 months ago

I think that if all that comes out of this is an official example that works as Peer-to-Peer and Dedicated Servers, that would be incredibly beneficial to the community, just based on the range of related questions I've run into while trying to figure this out.

AThousandShips commented 7 months ago

Transferred to the documentation repo as it belongs here and not in the main repo 🙂