Skip to content

Commit 4b58d28

Browse files
fix: NetworkVariable LastUpdateSent client timing (#3045)
* fix Use server time for NetworkVariableBase.LastUpdateSent time deltas when connected to a service or when not the server. * update Adding changelog entry * update adding PR number to entry.
1 parent 91bb80e commit 4b58d28

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2121
### Fixed
2222

2323
- Fixed issue where a NetworkObject hidden from a client that is then promoted to be session owner was not being synchronized with newly joining clients.(#3051)
24+
- Fixed issue where clients could have a wrong time delta on `NetworkVariableBase` which could prevent from sending delta state updates. (#3045)
2425
- Fixed issue where setting a prefab hash value during connection approval but not having a player prefab assigned could cause an exception when spawning a player. (#3042)
2526
- Fixed issue where the `NetworkSpawnManager.HandleNetworkObjectShow` could throw an exception if one of the `NetworkObject` components to show was destroyed during the same frame. (#3030)
2627
- Fixed issue where the `NetworkManagerHelper` was continuing to check for hierarchy changes when in play mode. (#3026)

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ public virtual void SetDirty(bool isDirty)
187187

188188
internal bool CanSend()
189189
{
190-
var timeSinceLastUpdate = m_NetworkBehaviour.NetworkManager.NetworkTimeSystem.LocalTime - LastUpdateSent;
190+
// When connected to a service or not the server, always use the synchronized server time as opposed to the local time
191+
var time = m_InternalNetworkManager.CMBServiceConnection || !m_InternalNetworkManager.IsServer ? m_NetworkBehaviour.NetworkManager.ServerTime.Time : m_NetworkBehaviour.NetworkManager.NetworkTimeSystem.LocalTime;
192+
var timeSinceLastUpdate = time - LastUpdateSent;
191193
return
192194
(
193195
UpdateTraits.MaxSecondsBetweenUpdates > 0 &&
@@ -201,7 +203,8 @@ internal bool CanSend()
201203

202204
internal void UpdateLastSentTime()
203205
{
204-
LastUpdateSent = m_NetworkBehaviour.NetworkManager.NetworkTimeSystem.LocalTime;
206+
// When connected to a service or not the server, always use the synchronized server time as opposed to the local time
207+
LastUpdateSent = m_InternalNetworkManager.CMBServiceConnection || !m_InternalNetworkManager.IsServer ? m_NetworkBehaviour.NetworkManager.ServerTime.Time : m_NetworkBehaviour.NetworkManager.NetworkTimeSystem.LocalTime;
205208
}
206209

207210
internal static bool IgnoreInitializeWarning;

0 commit comments

Comments
 (0)