diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
index 1b702e76fc..192882f6a5 100644
--- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
@@ -1092,7 +1092,10 @@ internal static void ResetSingleton()
///
public void SetSingleton()
{
- Singleton = this;
+ if (!Singleton || !Singleton.IsServer)
+ {
+ Singleton = this;
+ }
OnSingletonReady?.Invoke();
}
@@ -1401,7 +1404,14 @@ internal void InitializeNetcodeWorld()
/// !! Initialize worlds here !!
/// Worlds are created here:
UnifiedBootstrap.CurrentNetworkManagerForInitialization = this;
- DefaultWorldInitialization.Initialize("Default World", false);
+ if (UnifiedBootstrap.Instance != null)
+ {
+ UnifiedBootstrap.Instance.Initialize("Default World");
+ }
+ else
+ {
+ DefaultWorldInitialization.Initialize("Default World", false);
+ }
}
///
diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
index e9c4fe4693..f15eec1583 100644
--- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
@@ -3736,7 +3736,13 @@ private void Start()
private void InitGhost()
{
- if (!NetworkManager.IsListening)
+ if (!HasGhost || !NetworkObjectBridge || GhostAdapter.IsPrefab())
+ {
+ // Nothing to register
+ return;
+ }
+
+ if (!NetworkManager || !NetworkManager.IsListening)
{
if (NetworkManager.LogLevel == LogLevel.Developer)
{
@@ -3745,12 +3751,6 @@ private void InitGhost()
return;
}
- if (!HasGhost || !NetworkObjectBridge || GhostAdapter.IsPrefab())
- {
- // Nothing to register
- return;
- }
-
// All instances with Ghosts are automatically registered
if (NetworkManager.LogLevel == LogLevel.Developer)
{
diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs b/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs
index 82abbe2fd2..2c79ccab29 100644
--- a/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs
+++ b/com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs
@@ -2449,14 +2449,6 @@ internal void SpawnInstanceWithOwnership(NetworkObject networkObjectToSpawn, Net
}
else
{
-#if UNIFIED_NETCODE
- // TODO-FixMe: NetCode.Netcode.Instance is a singleton and might cause issues
- // assigning this.
- if (networkObjectToSpawn.HasGhost)
- {
- NetCode.Netcode.Instance.m_ActiveWorld = m_ServerNetworkManager.NetcodeWorld;
- }
-#endif
networkObjectToSpawn.NetworkManagerOwner = m_ServerNetworkManager; // Required to assure the server does the spawning
if (spawnAuthority == m_ServerNetworkManager)
{
diff --git a/testproject/Assets/Tests/Runtime/Support/NetworkObjectSpawnerForTests.cs b/testproject/Assets/Tests/Runtime/Support/NetworkObjectSpawnerForTests.cs
index f4102366fc..078d8ad107 100644
--- a/testproject/Assets/Tests/Runtime/Support/NetworkObjectSpawnerForTests.cs
+++ b/testproject/Assets/Tests/Runtime/Support/NetworkObjectSpawnerForTests.cs
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
+#if UNIFIED_NETCODE
+using Unity.NetCode;
+#endif
namespace TestProject.RuntimeTests
{
diff --git a/testproject/Assets/Tests/Runtime/TestProject.Runtime.Tests.asmdef b/testproject/Assets/Tests/Runtime/TestProject.Runtime.Tests.asmdef
index 51b61982a5..074cca9b5a 100644
--- a/testproject/Assets/Tests/Runtime/TestProject.Runtime.Tests.asmdef
+++ b/testproject/Assets/Tests/Runtime/TestProject.Runtime.Tests.asmdef
@@ -15,7 +15,8 @@
"Unity.Mathematics",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
- "Unity.Netcode.Runtime.Tests"
+ "Unity.Netcode.Runtime.Tests",
+ "Unity.NetCode"
],
"includePlatforms": [],
"excludePlatforms": [],