diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs
index 79035a895f..a9668084bd 100644
--- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs
@@ -13,6 +13,14 @@ namespace Unity.Netcode
[Serializable]
public class NetworkConfig
{
+ // Clamp spawn time outs to prevent dropping messages during scene events
+ // Note: The legacy versions of NGO defaulted to 1s which was too low. As
+ // well, the SpawnTimeOut is now being clamped to within this recommended
+ // range both via UI and when NetworkManager is validated.
+ internal const float MinSpawnTimeout = 10.0f;
+ // Clamp spawn time outs to no more than 1 hour (really that is a bit high)
+ internal const float MaxSpawnTimeout = 3600.0f;
+
///
/// The protocol version. Different versions doesn't talk to each other.
///
@@ -132,6 +140,8 @@ public class NetworkConfig
/// The amount of time a message will be held (deferred) if the destination NetworkObject needed to process the message doesn't exist yet. If the NetworkObject is not spawned within this time period, all deferred messages for that NetworkObject will be dropped.
///
[Tooltip("The amount of time a message will be held (deferred) if the destination NetworkObject needed to process the message doesn't exist yet. If the NetworkObject is not spawned within this time period, all deferred messages for that NetworkObject will be dropped.")]
+
+ [Range(MinSpawnTimeout, MaxSpawnTimeout)]
public float SpawnTimeout = 10f;
///
@@ -176,6 +186,21 @@ public class NetworkConfig
[Tooltip("Enable (default) if you want to profile network messages with development builds and defaults to being disabled in release builds. When disabled, network messaging profiling will be disabled in development builds.")]
public bool NetworkProfilingMetrics = true;
+ ///
+ /// Invoked by when it is validated.
+ ///
+ ///
+ /// Used to check for potential legacy values that have already been serialized and/or
+ /// runtime modifications to a property outside of the recommended range.
+ /// For each property checked below, provide a brief description of the reason.
+ ///
+ internal void OnValidate()
+ {
+ // Legacy NGO versions defaulted this value to 1 second that has since been determiend
+ // any range less than 10 seconds can lead to dropped messages during scene events.
+ SpawnTimeout = Mathf.Clamp(SpawnTimeout, MinSpawnTimeout, MaxSpawnTimeout);
+ }
+
///
/// Returns a base64 encoded version of the configuration
///
diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
index 6a7d71f159..4f8c56e1f4 100644
--- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
@@ -955,6 +955,9 @@ internal void OnValidate()
return; // May occur when the component is added
}
+ // Do a validation pass on NetworkConfig properties
+ NetworkConfig.OnValidate();
+
if (GetComponentInChildren() != null)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
index 5d94f4fd3c..1606343cca 100644
--- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
@@ -2007,12 +2007,14 @@ public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true)
internal bool InternalTrySetParent(NetworkObject parent, bool worldPositionStays = true)
{
- if (parent != null && (IsSpawned ^ parent.IsSpawned))
+ if (parent != null && (IsSpawned ^ parent.IsSpawned) && NetworkManager != null && !NetworkManager.ShutdownInProgress)
{
- if (NetworkManager != null && !NetworkManager.ShutdownInProgress)
+ if (NetworkManager.LogLevel <= LogLevel.Developer)
{
- return false;
+ var nameOfNotSpawnedObject = IsSpawned ? $" the parent ({parent.name})" : $"the child ({name})";
+ NetworkLog.LogWarning($"Parenting failed because {nameOfNotSpawnedObject} is not spawned!");
}
+ return false;
}
m_CachedWorldPositionStays = worldPositionStays;
diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs
index acffc411f8..8996dfcfd7 100644
--- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs
+++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs
@@ -1903,10 +1903,12 @@ private void OnSessionOwnerLoadedScene(uint sceneEventId, Scene scene)
SendSceneEventData(sceneEventData.SceneEventId, NetworkManager.ConnectedClientsIds.Where(c => c != sessionOwner).ToArray());
m_IsSceneEventActive = false;
+
+ sceneEventData.SceneEventType = SceneEventType.LoadComplete;
//First, notify local server that the scene was loaded
OnSceneEvent?.Invoke(new SceneEvent()
{
- SceneEventType = SceneEventType.LoadComplete,
+ SceneEventType = sceneEventData.SceneEventType,
LoadSceneMode = sceneEventData.LoadSceneMode,
SceneName = SceneNameFromHash(sceneEventData.SceneHash),
ClientId = NetworkManager.LocalClientId,