godot icon indicating copy to clipboard operation
godot copied to clipboard

The multiplayer instance isn't currently active

Open Regrad opened this issue 2 years ago • 13 comments

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())

Regrad avatar Jun 01 '23 08:06 Regrad

cc @Faless

Chaosus avatar Jun 01 '23 08:06 Chaosus

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.

Regrad avatar Jun 01 '23 08:06 Regrad

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."

Milan21y avatar Jun 24 '23 22:06 Milan21y

+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"

rametta avatar Jul 08 '23 13:07 rametta

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.

BurningFluffer avatar Jul 25 '23 22:07 BurningFluffer

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

RevoluPowered avatar Sep 27 '23 18:09 RevoluPowered

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 ?

Inna-7 avatar Nov 06 '23 06:11 Inna-7

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

church-basement avatar Nov 18 '23 01:11 church-basement

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

okay thanks

Inna-7 avatar Nov 21 '23 05:11 Inna-7

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()

church-basement avatar Nov 28 '23 20:11 church-basement

thanks bro kravohi

Devilhanilhan avatar Jan 14 '24 11:01 Devilhanilhan

Same here, Godot 4.3 dev6 as well.

CsloudX avatar Jun 07 '24 01:06 CsloudX

I am encountering the same. is there any direction on how to check if the multiplayer instance is active?

dev-bre avatar Sep 23 '24 19:09 dev-bre

I am encountering the same. is there any direction on how to check if the multiplayer instance is active?

You can use multiplayer.multiplayer_peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTED

Generally speaking, you can use the server_disconnected signal and create a new OfflineMultiplayerPeer. Unfortunately, if you have an autoload script which uses is_multiplayer_authority() in between the multiplayer_peer.close() and the server_disconnected signal, you get this error if you don't use the above check

yoba01 avatar Sep 29 '24 11:09 yoba01

this is a solution which is usable. thanks a lot for suggesting!

dev-bre avatar Oct 03 '24 14:10 dev-bre

Closing this as the following documentation PR has been merged: https://github.com/godotengine/godot-docs/pull/9087

skyace65 avatar Apr 15 '25 00:04 skyace65