Skip to content

Commit 3c122f8

Browse files
committed
Fix the fix
1 parent 11c10e4 commit 3c122f8

4 files changed

Lines changed: 16 additions & 37 deletions

File tree

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,7 @@ public bool IsNetworkVisibleTo(ulong clientId)
14431443
/// </summary>
14441444
internal Scene SceneOrigin
14451445
{
1446-
get
1447-
{
1448-
return m_SceneOrigin;
1449-
}
1446+
get => m_SceneOrigin;
14501447

14511448
set
14521449
{
@@ -1466,13 +1463,8 @@ internal Scene SceneOrigin
14661463
/// </summary>
14671464
internal NetworkSceneHandle GetSceneOriginHandle()
14681465
{
1469-
if (SceneOriginHandle.IsEmpty() && IsSpawned && InScenePlaced)
1470-
{
1471-
if (NetworkManager.LogLevel <= LogLevel.Error)
1472-
{
1473-
NetworkLog.LogErrorServer($"{nameof(GetSceneOriginHandle)} called when {nameof(SceneOriginHandle)} is still zero but the {nameof(NetworkObject)} is already spawned!");
1474-
}
1475-
}
1466+
NetworkLog.InternalAssert(!(IsSpawned && InScenePlaced && SceneOriginHandle.IsEmpty()), $"Spawned in scene placed NetworkObject {name} should always have a valid SceneOriginHandle");
1467+
14761468
return !SceneOriginHandle.IsEmpty() ? SceneOriginHandle : gameObject.scene.handle;
14771469
}
14781470

@@ -2057,7 +2049,6 @@ internal void SetupOnSpawn(ulong networkId, bool isPlayerObject, ulong ownerClie
20572049
NetworkObjectId = networkId;
20582050
IsPlayerObject = isPlayerObject;
20592051
OwnerClientId = ownerClientId;
2060-
m_IsOwner = ownerClientId == NetworkManagerOwner.LocalClientId;
20612052
// When spawned, previous owner is always the first assigned owner
20622053
PreviousOwnerId = ownerClientId;
20632054
m_HasAuthority = NetworkManagerOwner.DistributedAuthorityMode ? OwnerClientId == NetworkManagerOwner.LocalClientId : NetworkManagerOwner.IsServer;

com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,11 @@ private static bool TryGetNetworkObjectName([NotNull] NetworkManager networkMana
160160
return true;
161161
}
162162

163+
[HideInCallstack]
163164
[Conditional("NETCODE_INTERNAL")]
164165
internal static void InternalAssert(bool condition, string message)
165166
{
166167
Assert.IsTrue(condition, message);
167168
}
168-
169-
[Conditional("NETCODE_CHECK_OWNERSHIP")]
170-
internal static void OtherAssert(bool condition, string message)
171-
{
172-
Assert.IsTrue(condition, message);
173-
}
174169
}
175170
}

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,7 @@ internal void ServerResetShutdownStateForSceneObjects()
14611461
{
14621462
continue;
14631463
}
1464-
sobj.IsSpawned = false;
1465-
sobj.DestroyWithScene = false;
1464+
sobj.ResetOnDespawn();
14661465
}
14671466
}
14681467

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,17 @@ bool HasConditionBeenMet()
341341
Assert.False(s_GlobalTimeoutHelper.TimedOut, "Timed out while waiting for client side despawns!");
342342

343343
//----------- step 2 check spawn and destroy again
344-
authorityInstance.GetComponent<NetworkObject>().Spawn();
344+
var authorityObject = authorityInstance.GetComponent<NetworkObject>();
345+
authorityObject.Spawn();
346+
347+
// This validates invoking GetSceneOriginHandle will not throw an exception for a dynamically spawned NetworkObject
348+
// when the scene of origin hasn't been set.
349+
var sceneOriginHandle = authorityObject.GetSceneOriginHandle();
350+
351+
// This validates that GetSceneOriginHandle will return the GameObject's scene handle that should be the currently active scene
352+
var activeSceneHandle = SceneManager.GetActiveScene().handle;
353+
Assert.IsTrue(sceneOriginHandle == activeSceneHandle, $"{nameof(NetworkObject)} should have returned the active scene handle of {activeSceneHandle} but returned {sceneOriginHandle}");
354+
345355
// wait a tick
346356
yield return s_DefaultWaitForTick;
347357
// check spawned again on server this is 2 because we are reusing the object which was already spawned once.
@@ -366,22 +376,6 @@ bool HasConditionBeenMet()
366376
Assert.False(s_GlobalTimeoutHelper.TimedOut, "Timed out while waiting for client side despawns! (2nd pass)");
367377
}
368378

369-
[Test]
370-
public void DynamicallySpawnedNoSceneOriginException()
371-
{
372-
var gameObject = new GameObject();
373-
var networkObject = gameObject.AddComponent<NetworkObject>();
374-
networkObject.IsSpawned = true;
375-
networkObject.SceneOriginHandle = default;
376-
// This validates invoking GetSceneOriginHandle will not throw an exception for a dynamically spawned NetworkObject
377-
// when the scene of origin hasn't been set.
378-
var sceneOriginHandle = networkObject.GetSceneOriginHandle();
379-
380-
// This validates that GetSceneOriginHandle will return the GameObject's scene handle that should be the currently active scene
381-
var activeSceneHandle = SceneManager.GetActiveScene().handle;
382-
Assert.IsTrue(sceneOriginHandle == activeSceneHandle, $"{nameof(NetworkObject)} should have returned the active scene handle of {activeSceneHandle} but returned {sceneOriginHandle}");
383-
}
384-
385379
private class TrackOnSpawnFunctions : NetworkBehaviour
386380
{
387381
public int OnNetworkSpawnCalledCount { get; private set; }

0 commit comments

Comments
 (0)