Skip to content

Commit d6fb422

Browse files
committed
try things
1 parent edaf1fe commit d6fb422

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,13 @@ internal void InvokeOwnershipChanged(ulong previous, ulong next)
20602060

20612061
internal void InvokeBehaviourOnNetworkObjectParentChanged(NetworkObject parentNetworkObject)
20622062
{
2063+
if (NetworkManagerOwner == null)
2064+
{
2065+
#if TEST_NO_SINGLETON
2066+
Debug.LogError("NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton");
2067+
#endif
2068+
NetworkManagerOwner = NetworkManager.Singleton;
2069+
}
20632070
for (int i = 0; i < ChildNetworkBehaviours.Count; i++)
20642071
{
20652072
// Invoke internal notification
@@ -2288,6 +2295,13 @@ private void OnTransformParentChanged()
22882295

22892296
if (!IsSpawned)
22902297
{
2298+
if (NetworkManagerOwner == null)
2299+
{
2300+
#if TEST_NO_SINGLETON
2301+
Debug.LogError("NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton");
2302+
#endif
2303+
NetworkManagerOwner = NetworkManager;
2304+
}
22912305
AuthorityAppliedParenting = false;
22922306
// and we are removing the parent, then go ahead and allow parenting to occur
22932307
if (transform.parent == null)
@@ -2632,7 +2646,9 @@ private List<NetworkBehaviour> BuildChildBehavioursList()
26322646
{
26332647
if (NetworkManagerOwner == null)
26342648
{
2649+
#if TEST_NO_SINGLETON
26352650
Debug.LogError("NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton");
2651+
#endif
26362652
NetworkManagerOwner = NetworkManager.Singleton;
26372653
}
26382654

@@ -2759,6 +2775,15 @@ internal static void VerifyParentingStatus()
27592775
/// </returns>
27602776
public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
27612777
{
2778+
if (!IsSpawned)
2779+
{
2780+
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
2781+
{
2782+
Debug.LogWarning($"{nameof(NetworkObject)} is not spawned yet. Cannot get index of NetworkBehaviour.");
2783+
}
2784+
return 0;
2785+
}
2786+
27622787
// read the cached index, and verify it first
27632788
if (instance.NetworkBehaviourId < ChildNetworkBehaviours.Count)
27642789
{
@@ -2780,6 +2805,15 @@ public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
27802805
/// <returns>The <see cref="NetworkBehaviour"/> at the ordered index value or null if it does not exist.</returns>
27812806
public NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
27822807
{
2808+
if (!IsSpawned)
2809+
{
2810+
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
2811+
{
2812+
Debug.LogWarning($"{nameof(NetworkObject)} is not spawned yet. Cannot get NetworkBehaviour at index.");
2813+
}
2814+
return null;
2815+
}
2816+
27832817
if (index >= ChildNetworkBehaviours.Count)
27842818
{
27852819
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ internal NetworkObject InstantiateAndSpawnNoParameterChecks(NetworkObject networ
783783
return null;
784784
}
785785

786-
networkObject.NetworkManagerOwner = networkManager;
786+
networkObject.NetworkManagerOwner = NetworkManager;
787787
networkObject.IsPlayerObject = isPlayerObject;
788788
networkObject.transform.SetPositionAndRotation(position, rotation);
789789
// If spawning as a player, then invoke SpawnAsPlayerObject
@@ -1052,6 +1052,10 @@ internal void SpawnNetworkObjectLocally(NetworkObject networkObject, NetworkMana
10521052
}
10531053
}
10541054
// Invoke NetworkBehaviour.OnPreSpawn methods
1055+
if (networkObject.NetworkManagerOwner != networkManager || NetworkManager != networkManager)
1056+
{
1057+
Debug.LogWarning("overriding network manager");
1058+
}
10551059
networkObject.NetworkManagerOwner = networkManager;
10561060
networkObject.InvokeBehaviourNetworkPreSpawn();
10571061

@@ -1469,6 +1473,10 @@ internal void ServerSpawnSceneObjectsOnStartSweep()
14691473
var networkObjectsToSpawn = new List<NetworkObject>();
14701474
for (int i = 0; i < networkObjects.Length; i++)
14711475
{
1476+
if (networkObjects[i].NetworkManager != NetworkManager)
1477+
{
1478+
Debug.LogWarning("Well this is strange");
1479+
}
14721480
// This used to be two loops.
14731481
// The first added all NetworkObjects to a list and the second spawned all NetworkObjects in the list.
14741482
// Now, a parent will set its children's IsSceneObject value when spawned, so we check for null or for true.

com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/Components/ObjectNameIdentifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ public override void OnDestroy()
108108
DeRegisterNetworkObject();
109109
// This is required otherwise it will try to continue to update the NetworkBehaviour even if
110110
// it has been destroyed (most likely integration test specific)
111-
m_NetworkObject.ChildNetworkBehaviours?.Remove(this);
111+
if (m_NetworkObject.ChildNetworkBehaviours != null && m_NetworkObject.ChildNetworkBehaviours.Contains(this))
112+
{
113+
NetworkObject.ChildNetworkBehaviours.Remove(this);
114+
}
112115
m_NetworkObject = null;
113116
}
114117
base.OnDestroy();

0 commit comments

Comments
 (0)