Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ internal void InternalOnNetworkSpawn()
IsSpawned = true;
InitializeVariables();
UpdateNetworkProperties();
}

internal void VisibleOnNetworkSpawn()
{
OnNetworkSpawn();
}

Expand Down
7 changes: 7 additions & 0 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,13 @@ internal void InvokeBehaviourNetworkSpawn()
Debug.LogWarning($"{ChildNetworkBehaviours[i].gameObject.name} is disabled! Netcode for GameObjects does not support spawning disabled NetworkBehaviours! The {ChildNetworkBehaviours[i].GetType().Name} component was skipped during spawn!");
}
}
for (int i = 0; i < ChildNetworkBehaviours.Count; i++)
{
if (ChildNetworkBehaviours[i].gameObject.activeInHierarchy)
{
ChildNetworkBehaviours[i].VisibleOnNetworkSpawn();
}
}
}

internal void InvokeBehaviourNetworkDespawn()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UnityEngine;

namespace Unity.Netcode
{
Expand Down Expand Up @@ -79,7 +80,15 @@ protected NetworkVariableBase(
public virtual void SetDirty(bool isDirty)
{
m_IsDirty = isDirty;
if (m_IsDirty && m_NetworkBehaviour != null)

if (m_NetworkBehaviour == null)
{
Debug.LogWarning($"NetworkVariable is written to, but doesn't know its NetworkBehaviour yet. " +
"Are you modifying a NetworkVariable before the NetworkObject is spawned?");
return;
}

if (m_IsDirty)
{
m_NetworkBehaviour.NetworkManager.MarkNetworkObjectDirty(m_NetworkBehaviour.NetworkObject);
}
Expand Down