Skip to content

Commit f0046b4

Browse files
Merge branch 'develop-2.0.0' into experimental/v3-x-x/unified-poc-migration
2 parents 2c7d039 + c26b42e commit f0046b4

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

com.unity.netcode.gameobjects/CHANGELOG.md

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

2323
### Fixed
2424

25+
- Fixed issue where if the `NetworkManager` player prefab is not assigned an exception is thrown upon starting a host and/or when a client joins. (#3965)
2526

2627
### Security
2728

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Collections;
2+
using NUnit.Framework;
3+
using Unity.Netcode.TestHelpers.Runtime;
4+
using UnityEngine.TestTools;
5+
6+
namespace Unity.Netcode.RuntimeTests
7+
{
8+
/// <summary>
9+
/// Generic <see cref="NetworkManager"/> test to validate clients can connect
10+
/// without having set a player prefab.
11+
/// </summary>
12+
[TestFixture(HostOrServer.Server)]
13+
[TestFixture(HostOrServer.Host)]
14+
[TestFixture(HostOrServer.DAHost)]
15+
internal class NetworkManagerPlayerPrefab : NetcodeIntegrationTest
16+
{
17+
protected override int NumberOfClients => 1;
18+
19+
public NetworkManagerPlayerPrefab(HostOrServer hostOrServer) : base(hostOrServer)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Assure no player prefab is assigned.
25+
/// </summary>
26+
protected override void OnServerAndClientsCreated()
27+
{
28+
foreach (var networkManager in m_NetworkManagers)
29+
{
30+
networkManager.NetworkConfig.PlayerPrefab = null;
31+
}
32+
base.OnServerAndClientsCreated();
33+
}
34+
35+
protected override void OnNewClientCreated(NetworkManager networkManager)
36+
{
37+
networkManager.NetworkConfig.PlayerPrefab = null;
38+
base.OnNewClientCreated(networkManager);
39+
}
40+
41+
/// <summary>
42+
/// Do not wait for spawned players as there are none.
43+
/// </summary>
44+
/// <returns></returns>
45+
protected override bool ShouldCheckForSpawnedPlayers()
46+
{
47+
return false;
48+
}
49+
50+
/// <summary>
51+
/// Validates NetworkManager can start as a host and/or clients
52+
/// can join when there is no player prefab assigned to the
53+
/// NetworkManager.
54+
/// </summary>
55+
[UnityTest]
56+
public IEnumerator VerifyNetworkManagerHandlesNoPlayerPrefab()
57+
{
58+
// If we make it to here, then the 1st client and the authority
59+
// connected with no exceptions.
60+
// Now just late join a 2nd client.
61+
yield return CreateAndStartNewClient();
62+
// If it makes it to here without an exception then the test passes.
63+
}
64+
}
65+
}

com.unity.netcode.gameobjects/Tests/Runtime/NetworkManagerPlayerPrefab.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,12 @@ protected virtual void OnTimeTravelServerAndClientsConnected()
11681168
private void ClientNetworkManagerPostStart(NetworkManager networkManager)
11691169
{
11701170
networkManager.name = $"NetworkManager - Client - {networkManager.LocalClientId}";
1171+
1172+
// Always make sure we have a player to check.
1173+
if (!ShouldCheckForSpawnedPlayers())
1174+
{
1175+
return;
1176+
}
11711177
Assert.NotNull(networkManager.LocalClient.PlayerObject, $"{nameof(StartServerAndClients)} detected that client {networkManager.LocalClientId} does not have an assigned player NetworkObject!");
11721178

11731179
// Go ahead and create an entry for this new client

0 commit comments

Comments
 (0)