godotengine / godot

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

`MultiplayerPeer.get_connection_status()` returns `CONNECTION_CONNECTED` while disconnected #75049

Open ana-rchy opened 1 year ago

ana-rchy commented 1 year ago

Godot version

4.0.stable

System information

linux 6.2.6-arch1-1-vfio

Issue description

get_connection_status() is intended to return CONNECTION_DISCONNECTED if theres no connection with any peer/server made, but because multiplayer.multiplayer_peer contains a value (that returns <OfflineMultiplayerPeer#-[client id]> when printed), im assuming the engine is still expecting a return value of null like in godot 3.x

Steps to reproduce

print(multiplayer.multiplayer_peer.get_connection_status()) on any node any time theres no connection made with MultiplayerAPI

or just run minimal reproduction project

Minimal reproduction project

connection status minimal reproduction.zip

Faless commented 1 year ago

This is expected behavior in 4.0 where the OfflineMultiplayerPeer is active by default (#68689). You can revert to the old behavior by explicitly setting multiplyaer.multiplayer_peer = null.

Faless commented 1 year ago

I'm reopening the issue following the discussion in #75121.

While I'm not particularly fond of either proposed solutions, I do acknowledge the confusion generated by the API, and that we need a clearer path to detect online/offline state.

ana-rchy commented 1 year ago

i got embarassed because i realized my fix that mentioned this was probably useless so i abandoned it but now its useful again wtf