godotengine / godot

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

HasMultiplayerPeer is always true in Godot C# #85131

Closed MartSchilt closed 11 months ago

MartSchilt commented 12 months ago

Godot version

4.1.3.stable

System information

Godot v4.1.3.stable.mono - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 SUPER (NVIDIA; 31.0.15.3699) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)

Issue description

Using C# with Godot 4.1.3 I get the following: I setup a peer-to-peer connection using Godot's 'Multiplayer' class (MultiplayerAPI) and call the method HasPeers(). This should return true if there are any peers connected. Right now this always returns true.

I only want this to return true if there are peers connected (so not only yourself). I fixed this locally in my code by changing it to "Multiplayer.GetPeers().Length > 0"

Steps to reproduce

Create a ENetMultiplayerPeer and then call Multiplayer.HasPeers()

Minimal reproduction project

N/A

ShlomiRex commented 12 months ago

ENetMultiplayerPeer doesn't have functions HasPeers() or GetPeers() or is it just me? https://docs.godotengine.org/en/stable/classes/class_enetmultiplayerpeer.html

AThousandShips commented 12 months ago

MultiplayerAPI has get_peers and has_multiplayer_peer, no has_peers though

ShlomiRex commented 12 months ago

Please provide basic C# code so I can reproduce it

AThousandShips commented 12 months ago

Please provide a minimal reproduction project:

And please make sure it's specific to C#

MartSchilt commented 12 months ago

HasMultiplayerPeer Bug.zip

AThousandShips commented 12 months ago

This is because there's always a default OfflineMultiplayerPeer, see here

MartSchilt commented 12 months ago

But why doesn't it then show up in the list of peers from GetPeers?

Also the documentation states that "It mimics the behavior of a server with no peers connected" meaning that there are no peers, so I would expect HasMultiplayerPeers to return false

AThousandShips commented 12 months ago

It isn't has_multiplayer_peers it's has_multiplayer_peer, it isn't about connected peers, but the peer on your end:

Returns true if there is a multiplayer_peer set.

It isn't about any peers connected

MartSchilt commented 11 months ago

Well if that is the desired functionality, I will close this issue