You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
20
20
### Removed
21
21
22
22
### Fixed
23
+
- Fixed issue where dynamically spawned `NetworkObject`s could throw an exception if the scene of origin handle was zero (0) and the `NetworkObject` was already spawned. (#2017)
23
24
- Fixed issue where `NetworkObject.Observers` was not being cleared when despawned. (#2009)
24
25
- Fixed `NetworkAnimator` could not run in the server authoritative mode. (#2003)
25
26
- Fixed issue where late joining clients would get a soft synchronization error if any in-scene placed NetworkObjects were parented under another `NetworkObject`. (#1985)
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -221,8 +221,7 @@ internal Scene SceneOrigin
221
221
/// </summary>
222
222
internal int GetSceneOriginHandle()
223
223
{
224
-
// Sanity check to make sure nothing
225
-
if (SceneOriginHandle == 0 && IsSpawned)
224
+
if (SceneOriginHandle == 0 && IsSpawned && IsSceneObject != false)
226
225
{
227
226
throw new Exception($"{nameof(GetSceneOriginHandle)} called when {nameof(SceneOriginHandle)} is still zero but the {nameof(NetworkObject)} is already spawned!");
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,23 @@ bool HasConditionBeenMet()
168
168
Assert.False(s_GlobalTimeoutHelper.TimedOut, "Timed out while waiting for client side despawns! (2nd pass)");
169
169
}
170
170
171
+
[Test]
172
+
public void DynamicallySpawnedNoSceneOriginException()
173
+
{
174
+
var gameObject = new GameObject();
175
+
var networkObject = gameObject.AddComponent<NetworkObject>();
176
+
networkObject.IsSpawned = true;
177
+
networkObject.SceneOriginHandle = 0;
178
+
networkObject.IsSceneObject = false;
179
+
// This validates invoking GetSceneOriginHandle will not throw an exception for a dynamically spawned NetworkObject
180
+
// when the scene of origin handle is zero
181
+
var sceneOriginHandle = networkObject.GetSceneOriginHandle();
182
+
183
+
// This validates that GetSceneOriginHandle will return the GameObject's scene handle that should be the currently active scene
184
+
var activeSceneHandle = UnityEngine.SceneManagement.SceneManager.GetActiveScene().handle;
185
+
Assert.IsTrue(sceneOriginHandle == activeSceneHandle, $"{nameof(NetworkObject)} should have returned the active scene handle of {activeSceneHandle} but returned {sceneOriginHandle}");
186
+
}
187
+
171
188
private class TrackOnSpawnFunctions : NetworkBehaviour
172
189
{
173
190
public int OnNetworkSpawnCalledCount { get; private set; }
0 commit comments