godotengine / godot

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

The multiplayer instance isn't currently active #77723

Open Regrad opened 1 year ago

Regrad commented 1 year ago

Godot version

4.0.3

System information

Windows 11

Issue description

When starting the game (multiplayer server not started), if do "print (is_multiplayer_authority())" gives "True", but after server_custom.close () (close the server) an error starts to appear "The multiplayer instance isn't currently active". Thus, all further calls to network functions begin to produce errors. Thus, if a player after a network game wants to go into a single player game, the game will spam errors. If he starts a single player game right away, there will be no errors. This problem occurs not only with "is_multiplayer_authority()", but also with some other network functions or nodes.

I think is_multiplayer_authority() should either throw an error right away (it returns true now before the server is created, as if Godot is running the server by default) or not throw any errors after the server is closed. The second option is much more preferable. I hope I managed to explain the problem.

Steps to reproduce

Before starting the server, check "print (is_multiplayer_authority())", then start the server, close it and check again

Minimal reproduction project

var server_custom = ENetMultiplayerPeer.new()

func _ready():
    print (is_multiplayer_authority())
    server_custom.create_server(4530, 9)
    multiplayer.multiplayer_peer = server_custom
    server_custom.close()
    print (is_multiplayer_authority())
Chaosus commented 1 year ago

cc @Faless

Regrad commented 1 year ago

I also noticed that get_parent().add_child also causes error "The multiplayer instance isn't currently active" in this situation. It is very strange. Perhaps this is due to MultiplayerSpawner.

Milan21y commented 1 year ago

i had a similar setup to this one, i quit the game and a few of these errors you mention showed up to me where i checked for authority what i found interesting though is that if i tried rejoining the server, the "get_unique_id()" function also returns an error. "The multiplayer instance isn't currently active."

rametta commented 1 year ago

+1 also experiencing this error. I am using the MultiplayerSpawner. On my server, before I call enet_peer.close(), I first call enet_peer.disconnect_peer(peer) for every peer connected to the server so every client can handle the server closing gracefully. But I am getting these errors of The multiplayer instance isn't currently active. when the call to is_multiplayer_authority() happens inside my _physics_process() on my clients that get disconnected

Currently using "Godot 4.1.stable"

BurningFluffer commented 1 year ago

Same here, Godot 4.1.stable as well. tried with enet_peer.disconnect_peer(peer) and without, always getting this error in _process() and _unhandled_input() for both client and server, though turning server or client on again fixes it and returns controls. Manually created a variable to for that script to not bother checking if my in_multiplayer == false, one working workaround for now.

RevoluPowered commented 11 months ago

We're getting this on the mirror and it's causing us some issues when rejoining game sessions.

If _is_active was exposed we could use this and just check the status in our own wrappers/code.

image

Inna-7 commented 9 months ago

We're getting this on the mirror and it's causing us some issues when rejoining game sessions.

If _is_active was exposed we could use this and just check the status in our own wrappers/code.

image

Can you show an example please using _is_active in code to avoid that errors ?

kravohi commented 9 months ago

yup having the same problem, after calling enet_peer.close() any place in the code that uses multiplayer throws the error.

Inna-7 commented 9 months ago

yup having the same problem, after calling enet_peer.close() any place in the code that uses multiplayer throws the error.

okay thanks

kravohi commented 9 months ago

I found a work around, or perhaps how its intended to be done? I noticed that at the startup of a game multiplayer.multiplayer_peer equals a instance of OfflineMultiplayerPeer, so... Closing the server like this works, and the error The multiplayer instance isn't currently active is no longer thrown. multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new() enet_server.close()

Devilhanilhan commented 7 months ago

thanks bro kravohi

CsloudX commented 2 months ago

Same here, Godot 4.3 dev6 as well.