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
3 changes: 3 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- Added `NetworkTransport.OnEarlyUpdate` and `NetworkTransport.OnPostLateUpdate` methods to provide more control over handling transport related events at the start and end of each frame. (#3113)

### Fixed

- Fixed issue where queued UnitTransport (NetworkTransport) message batches were being sent on the next frame. They are now sent at the end of the frame during `PostLateUpdate`. (#3113)
- Fixed issue where `NotOwnerRpcTarget` or `OwnerRpcTarget` were not using their replacements `NotAuthorityRpcTarget` and `AuthorityRpcTarget` which would invoke a warning. (#3111)
- Fixed issue where client is removed as an observer from spawned objects when their player instance is despawned. (#3110)
- Fixed issue where `NetworkAnimator` would statically allocate write buffer space for `Animator` parameters that could cause a write error if the number of parameters exceeded the space allocated. (#3108)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,18 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
case NetworkUpdateStage.EarlyUpdate:
{
UpdateTopology();

// Handle processing any new connections or transport events
NetworkConfig.NetworkTransport.EarlyUpdate();

ConnectionManager.ProcessPendingApprovals();
ConnectionManager.PollAndHandleNetworkEvents();

DeferredMessageManager.ProcessTriggers(IDeferredNetworkMessageManager.TriggerType.OnNextFrame, 0);

AnticipationSystem.SetupForUpdate();
MessageManager.ProcessIncomingMessageQueue();

MessageManager.CleanupDisconnectedClients();
AnticipationSystem.ProcessReanticipation();
}
Expand Down Expand Up @@ -379,6 +384,9 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
// Metrics update needs to be driven by NetworkConnectionManager's update to assure metrics are dispatched after the send queue is processed.
MetricsManager.UpdateMetrics();

// Handle sending any pending transport messages
NetworkConfig.NetworkTransport.PostLateUpdate();

// TODO: Determine a better way to handle this
NetworkObject.VerifyParentingStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,45 @@ protected void InvokeOnTransportEvent(NetworkEvent eventType, ulong clientId, Ar
/// /// <param name="networkManager">optionally pass in NetworkManager</param>
public abstract void Initialize(NetworkManager networkManager = null);

/// <summary>
/// Invoked by NetworkManager at the beginning of its EarlyUpdate.
/// For order of operations see: <see cref="NetworkManager.NetworkUpdate(NetworkUpdateStage)"/>
/// </summary>
/// Useful to handle processing any transport-layer events such as processing inbound messages or changes in connection state(s).
/// </remarks>
protected virtual void OnEarlyUpdate()
{

}

/// <summary>
/// Invoked by NetworkManager at the beginning of its EarlyUpdate
/// </summary>
internal void EarlyUpdate()
{
OnEarlyUpdate();
}

/// <summary>
/// Invoked by NetworkManager towards the end of the PostLateUpdate.
/// For order of operations see: <see cref="NetworkManager.NetworkUpdate(NetworkUpdateStage)"/>
/// </summary>
/// <remarks>
/// Useful to handle any end of frame transport tasks such as sending queued transport messages.
/// </remarks>
protected virtual void OnPostLateUpdate()
{

}

/// <summary>
/// Invoked by NetworkManager towards the end of the PostLateUpdate
/// </summary>
internal void PostLateUpdate()
{
OnPostLateUpdate();
}

protected virtual NetworkTopologyTypes OnCurrentTopology()
{
return NetworkTopologyTypes.ClientServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,17 +944,13 @@ private bool ProcessEvent()
return false;
}

private void Update()
/// <summary>
/// Handles accepting new connections and processing transport events.
/// </summary>
protected override void OnEarlyUpdate()
{
if (m_Driver.IsCreated)
{
foreach (var kvp in m_SendQueue)
{
SendBatchedMessages(kvp.Key, kvp.Value);
}

m_Driver.ScheduleUpdate().Complete();

if (m_ProtocolType == ProtocolType.RelayUnityTransport && m_Driver.GetRelayConnectionStatus() == RelayConnectionStatus.AllocationInvalid)
{
Debug.LogError("Transport failure! Relay allocation needs to be recreated, and NetworkManager restarted. " +
Expand All @@ -964,15 +960,38 @@ private void Update()
return;
}

m_Driver.ScheduleUpdate().Complete();

// Process any new connections
while (AcceptConnection() && m_Driver.IsCreated)
{
;
}

// Process any transport events (i.e. connect, disconnect, data, etc)
while (ProcessEvent() && m_Driver.IsCreated)
{
;
}
}
base.OnEarlyUpdate();
}

/// <summary>
/// Handles sending any queued batched messages.
/// </summary>
protected override void OnPostLateUpdate()
{
if (m_Driver.IsCreated)
{
foreach (var kvp in m_SendQueue)
{
SendBatchedMessages(kvp.Key, kvp.Value);
}

// Schedule a flush send as the last transport action for the
// current frame.
m_Driver.ScheduleFlushSend(default).Complete();

#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
if (m_NetworkManager)
Expand All @@ -981,6 +1000,7 @@ private void Update()
}
#endif
}
base.OnPostLateUpdate();
}

private void OnDestroy()
Expand Down Expand Up @@ -1452,6 +1472,11 @@ public override void Shutdown()
{
if (m_Driver.IsCreated)
{
while (ProcessEvent() && m_Driver.IsCreated)
{
;
}

// Flush all send queues to the network. NGO can be configured to flush its message
// queue on shutdown. But this only calls the Send() method, which doesn't actually
// get anything to the network.
Expand Down
Loading
Loading