Skip to content

Commit 187d6ea

Browse files
update
Exit early if trying to start in hybrid mode but not configured for a single world.
1 parent b9446a4 commit 187d6ea

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#endif
1515
using UnityEngine.SceneManagement;
1616
using Debug = UnityEngine.Debug;
17+
using Unity.NetCode;
1718

1819

1920
namespace Unity.Netcode
@@ -1342,6 +1343,22 @@ private System.Collections.IEnumerator WaitForHybridPrefabRegistration(StartType
13421343
}
13431344
}
13441345
}
1346+
1347+
private bool UnifiedIsConfiguredCorrectly()
1348+
{
1349+
if (NetCodeConfig.Global == null)
1350+
{
1351+
Debug.LogError($"[{nameof(NetworkManager)}][Unified] You must create a {nameof(NetCodeConfig)} and set it to a single world in order to run in hybrid mode!");
1352+
return false;
1353+
}
1354+
if (NetCodeConfig.Global.HostWorldModeSelection != NetCodeConfig.HostWorldMode.SingleWorld)
1355+
{
1356+
Debug.LogError($"[{nameof(NetworkManager)}][Unified] You must configure {nameof(NetCodeConfig)} to only use a single world in order to run in hybrid mode!");
1357+
return false;
1358+
}
1359+
return true;
1360+
}
1361+
13451362
#endif
13461363

13471364
/// <summary>
@@ -1372,6 +1389,13 @@ public bool StartServer()
13721389
// TODO-UNIFIED: Review and align on this being a way to handle knowing if the world should be created.
13731390
if (NetworkConfig.Prefabs.HasGhostPrefabs)
13741391
{
1392+
if (!UnifiedIsConfiguredCorrectly())
1393+
{
1394+
m_ShuttingDown = true;
1395+
ShutdownInternal();
1396+
return false;
1397+
}
1398+
NetCodeConfig.Global.HostWorldModeSelection = NetCodeConfig.HostWorldMode.SingleWorld;
13751399
DefaultWorldInitialization.Initialize("Default World", false);
13761400
StartCoroutine(WaitForHybridPrefabRegistration(StartType.Server));
13771401
return true;
@@ -1440,6 +1464,13 @@ public bool StartClient()
14401464
// TODO-UNIFIED: Review and align on this being a way to handle knowing if the world should be created.
14411465
if (NetworkConfig.Prefabs.HasGhostPrefabs)
14421466
{
1467+
if (!UnifiedIsConfiguredCorrectly())
1468+
{
1469+
m_ShuttingDown = true;
1470+
ShutdownInternal();
1471+
return false;
1472+
}
1473+
14431474
DefaultWorldInitialization.Initialize("Default World", false);
14441475
StartCoroutine(WaitForHybridPrefabRegistration(StartType.Client));
14451476
// TODO-UNIFIED: Need a way to signal everything completed.
@@ -1508,6 +1539,13 @@ public bool StartHost()
15081539
// TODO-UNIFIED: Review and align on this being a way to handle knowing if the world should be created.
15091540
if (NetworkConfig.Prefabs.HasGhostPrefabs)
15101541
{
1542+
if (!UnifiedIsConfiguredCorrectly())
1543+
{
1544+
m_ShuttingDown = true;
1545+
ShutdownInternal();
1546+
return false;
1547+
}
1548+
15111549
DefaultWorldInitialization.Initialize("Default World", false);
15121550
StartCoroutine(WaitForHybridPrefabRegistration(StartType.Host));
15131551
// TODO-UNIFIED: Need a way to signal everything completed.

0 commit comments

Comments
 (0)