diff --git a/core/io/networked_multiplayer_custom.cpp b/core/io/networked_multiplayer_custom.cpp
index 75fc85211ed..4c1137f4a5c 100644
--- a/core/io/networked_multiplayer_custom.cpp
+++ b/core/io/networked_multiplayer_custom.cpp
@@ -139,9 +139,10 @@ NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerCustom::get_conne
//
void NetworkedMultiplayerCustom::initialize(int p_self_id) {
- if (connection_status != ConnectionStatus::CONNECTION_CONNECTING) {
- return;
- }
+ ERR_FAIL_COND_MSG(connection_status != ConnectionStatus::CONNECTION_CONNECTING,
+ "Can only initialize if connection status is CONNECTION_CONNECTING.");
+ ERR_FAIL_COND_MSG(p_self_id < 0 || p_self_id > ~(1 << 31),
+ "Cannot initialize with invalid unique network id.");
self_id = p_self_id;
if (self_id == 1) {
@@ -159,9 +160,9 @@ void NetworkedMultiplayerCustom::set_connection_status(NetworkedMultiplayerPeer:
}
ERR_FAIL_COND_MSG(p_connection_status == ConnectionStatus::CONNECTION_CONNECTING && connection_status != ConnectionStatus::CONNECTION_DISCONNECTED,
- "Can only change connection status to CONNECTION_CONNECTING from CONNECTION_DISCONNECTED");
+ "Can only change connection status to CONNECTION_CONNECTING from CONNECTION_DISCONNECTED.");
ERR_FAIL_COND_MSG(p_connection_status == ConnectionStatus::CONNECTION_CONNECTED && connection_status != ConnectionStatus::CONNECTION_CONNECTING,
- "Can only change connection status to CONNECTION_CONNECTED from CONNECTION_CONNECTING");
+ "Can only change connection status to CONNECTION_CONNECTED from CONNECTION_CONNECTING.");
if (p_connection_status == ConnectionStatus::CONNECTION_CONNECTED) {
connection_status = p_connection_status;
diff --git a/doc/classes/NetworkedMultiplayerCustom.xml b/doc/classes/NetworkedMultiplayerCustom.xml
index f336dc521e0..f0a88cd2449 100644
--- a/doc/classes/NetworkedMultiplayerCustom.xml
+++ b/doc/classes/NetworkedMultiplayerCustom.xml
@@ -24,6 +24,7 @@
Initialize the peer with the given [code]peer_id[/code] (must be between 1 and 2147483647).
+ Can only be called if the connection status is [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING]. See [method set_connection_status].
@@ -32,7 +33,7 @@
Set the state of the connection. See [enum NetworkedMultiplayerPeer.ConnectionStatus].
This will emit the [signal NetworkedMultiplayerPeer.connection_succeeded], [signal NetworkedMultiplayerPeer.connection_failed] or [signal NetworkedMultiplayerPeer.server_disconnected] signals depending on the status and if the peer has the unique network id of [code]1[/code].
- You can only change to [code]CONNECTION_CONNECTING[/code] from [code]CONNECTION_DISCONNECTED[/code] and to [code]CONNECTION_CONNECTED[/code] from [code]CONNECTION_CONNECTING[/code].
+ You can only change to [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING] from [constant NetworkedMultiplayerPeer.CONNECTION_DISCONNECTED] and to [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] from [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING].