Skip to content

Commit ce720f2

Browse files
style
Updated and added some comments to the region of code that contains the primary fix.
1 parent fd5ba9b commit ce720f2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,8 +2556,12 @@ internal void InvokeBehaviourNetworkSpawn()
25562556
{
25572557
NetworkManager.SpawnManager.UpdateOwnershipTable(this, OwnerClientId);
25582558

2559-
// Always invoke all internal network spawn methods on each child NetworkBehaviour
2559+
// Always invoke all InternalOnNetworkSpawn methods on each child NetworkBehaviour
25602560
// ** before ** invoking OnNetworkSpawn.
2561+
// This assures all NetworkVariables and RPC related tables have been initialized
2562+
// prior to invoking OnNetworkSpawn so cross NetworkBehaviour:
2563+
// - accessing of NetworkVariables will work correctly.
2564+
// - invocation of RPCs will work properly (and not throw exception under certain scenarios)
25612565
foreach (var childBehaviour in ChildNetworkBehaviours)
25622566
{
25632567
if (!childBehaviour.gameObject.activeInHierarchy)
@@ -2568,7 +2572,7 @@ internal void InvokeBehaviourNetworkSpawn()
25682572
childBehaviour.InternalOnNetworkSpawn();
25692573
}
25702574

2571-
// Invoke OnNetworkSpawn on each child NetworkBehaviour
2575+
// After initialization, we can then invoke OnNetworkSpawn on each child NetworkBehaviour.
25722576
foreach (var childBehaviour in ChildNetworkBehaviours)
25732577
{
25742578
if (!childBehaviour.gameObject.activeInHierarchy)
@@ -2591,7 +2595,6 @@ internal void InvokeBehaviourNetworkPostSpawn()
25912595
}
25922596
}
25932597

2594-
25952598
internal void InternalNetworkSessionSynchronized()
25962599
{
25972600
for (int i = 0; i < ChildNetworkBehaviours.Count; i++)

0 commit comments

Comments
 (0)