Skip to content

Commit 993c3d8

Browse files
fix: NetworkConfig cached hash was not being regenerated on clients for each unique ConnectionRequestMessage [MTT-4605] (#2226)
MTT-4605 * fix This resolves the issue where clients would not regenerate their NetworkConfig's hash value if a client disconnected from one server and tried to join another server. * test This validates that passing false to the NetworkConfig.GetConfig method generates a unique hash value. * update updating the changelog entry with the PR number.
1 parent 14c26fe commit 993c3d8

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2121

2222
### Fixed
2323

24+
- Fixed issue where clients were not rebuilding the `NetworkConfig` hash value for each unique connection request. (#2226)
2425
- Fixed the issue where player objects were not taking the `DontDestroyWithOwner` property into consideration when a client disconnected. (#2225)
2526
- Fixed issue #1924 where `UnityTransport` would fail to restart after a first failure (even if what caused the initial failure was addressed). (#2220)
2627
- Fixed issue where `NetworkTransform.SetStateServerRpc` and `NetworkTransform.SetStateClientRpc` were not honoring local vs world space settings when applying the position and rotation. (#2203)

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,9 @@ private void SendConnectionRequest()
16091609
{
16101610
var message = new ConnectionRequestMessage
16111611
{
1612-
ConfigHash = NetworkConfig.GetConfig(),
1612+
// Since only a remote client will send a connection request,
1613+
// we should always force the rebuilding of the NetworkConfig hash value
1614+
ConfigHash = NetworkConfig.GetConfig(false),
16131615
ShouldSendConnectionData = NetworkConfig.ConnectionApproval,
16141616
ConnectionData = NetworkConfig.ConnectionData
16151617
};

com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,27 @@ private void NetworkManagerObject_ConnectionApprovalCallback(NetworkManager.Conn
6262
response.PlayerPrefabHash = null;
6363
}
6464

65+
66+
[Test]
67+
public void VerifyUniqueNetworkConfigPerRequest()
68+
{
69+
var networkConfig = new NetworkConfig();
70+
networkConfig.EnableSceneManagement = true;
71+
networkConfig.TickRate = 30;
72+
var currentHash = networkConfig.GetConfig();
73+
networkConfig.EnableSceneManagement = false;
74+
networkConfig.TickRate = 60;
75+
var newHash = networkConfig.GetConfig(false);
76+
77+
Assert.True(currentHash != newHash, $"Hashed {nameof(NetworkConfig)} values {currentHash} and {newHash} should not be the same!");
78+
}
79+
6580
[TearDown]
6681
public void TearDown()
6782
{
6883
// Stop, shutdown, and destroy
6984
NetworkManagerHelper.ShutdownNetworkManager();
7085
}
86+
7187
}
7288
}

0 commit comments

Comments
 (0)