godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.35k stars 20.01k forks source link

Godot ENetConnection.service() doesn't work with multiplayer.multiplayer_peer.host #87811

Open maticstric opened 6 months ago

maticstric commented 6 months ago

Tested versions

System information

MacOS 12.5 - Godot v4.2.stable.official

Issue description

The service() function should return an EVENT_CONNECT when a new player connects. This works if I simply create an ENetMultiplayerPeer and create_server or create_client, however, as soon as I set the multiplayer.multiplayer_peer variable to this newly created ENetMultiplayerPeer, the service() function no longer returns any non-zero events.

Steps to reproduce

Open the MRP. Set the project to open two instances (Debug -> Run Multiple Instances -> Run 2 Instances). Run the project. Click the host button on one instance and then join on the other. You would expect some prints (two since there's two connections), but nothing happens.

I also have some commented lines to show that it does work as long as I don't set the multiplayer.multiplayer_peer variable. Uncomment line 12. Comment lines 13, 22, and 30. Again, run project and click host and join. You should see some printouts from the non-zero event (print on line 16).

Minimal reproduction project (MRP)

demo.zip

maticstric commented 6 months ago

Bump

Faless commented 6 months ago

@maticstric please don't bump issues without adding more information.

Opening issues in random maintainers repositories is also very impolite.

Faless commented 6 months ago

This is mostly a documentation issue (we could add some extra checks in code to throw an error).

The ENetConnection.service function should not be called when using the ENetMultiplayerPeer, since that is used internally by ENetMultiplayerPeer.poll() and calling it manually will prevent the multiplayer peer from working correctly.

maticstric commented 6 months ago

My bad.

The documentation for using Godot multiplayer without its "High-level multiplayer" features is pretty much non-existent, so I felt I didn't have a good way forward. Had to spend a few days looking at source code to figure out what I'm supposed to do. Still not sure if I totally get it, but ENetConnection seems to be the important class. It would be nice to mention this somewhere or maybe have a simple example project. There don't even seem to be random online (blog, youtube, etc.) tutorials for this.

For a beginner to Godot multiplayer it's very hard to keep track of the differences between the many ENet/Multiplayer classes in Godot (MultiplayerAPI, ENetMultiplayerPeer, MultiplayerPeer, PacketPeer, ENetConnection, ENetPacketPeer, etc.).

Thanks for the help!