Skip to content

Commit 5b35d26

Browse files
update
Removing exception. Adjusting when we update the last time. Logging warning if log level is developer and there is no NetworkTimeSystem.
1 parent 9fafd5f commit 5b35d26

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,9 @@ public void Initialize(NetworkBehaviour networkBehaviour)
104104
}
105105
m_InternalNetworkManager = m_NetworkBehaviour.NetworkObject.NetworkManagerOwner;
106106

107-
// Throw an exception if there is no valid NetworkTimeSystem
108-
if (m_InternalNetworkManager.NetworkTimeSystem == null)
109-
{
110-
throw new Exception($"[{m_NetworkBehaviour.name}][{m_NetworkBehaviour.GetType().Name}][{GetType().Name}][Initialize] {nameof(NetworkManager)} has no {nameof(NetworkTimeSystem)} assigned!");
111-
}
112-
113107
// When in distributed authority mode, there is no such thing as server write permissions
114108
InternalWritePerm = m_InternalNetworkManager.DistributedAuthorityMode ? NetworkVariableWritePermission.Owner : InternalWritePerm;
115109

116-
// Update our last sent time relative to when this was initialized
117-
UpdateLastSentTime();
118-
119110
// Wrap potential user script override to catch and log any exceptions
120111
try
121112
{
@@ -126,8 +117,20 @@ public void Initialize(NetworkBehaviour networkBehaviour)
126117
Debug.LogException(ex);
127118
}
128119

129-
// At this point, this instance is considered initialized
130-
HasBeenInitialized = true;
120+
// Some unit tests don't operate with a running NetworkManager.
121+
// Only update the last time if there is a NetworkTimeSystem.
122+
if (m_InternalNetworkManager.NetworkTimeSystem != null)
123+
{
124+
// Update our last sent time relative to when this was initialized
125+
UpdateLastSentTime();
126+
127+
// At this point, this instance is considered initialized
128+
HasBeenInitialized = true;
129+
}
130+
else if (m_InternalNetworkManager.LogLevel == LogLevel.Developer)
131+
{
132+
Debug.LogWarning($"[{m_NetworkBehaviour.name}][{m_NetworkBehaviour.GetType().Name}][{GetType().Name}][Initialize] {nameof(NetworkManager)} has no {nameof(NetworkTimeSystem)} assigned!");
133+
}
131134
}
132135

133136
/// <summary>

0 commit comments

Comments
 (0)