Skip to content

Commit a61547c

Browse files
update
Splitting up accepting a connection and process event. Migrating process event into the PreUpdate but after time has updated.
1 parent da91e02 commit a61547c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
333333
{
334334
NetworkTimeSystem.UpdateTime();
335335
AnticipationSystem.Update();
336+
// Transport processes events after time has been updated
337+
NetworkConfig.NetworkTransport.PreUpdate();
336338
}
337339
break;
338340
case NetworkUpdateStage.PreLateUpdate:

com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ internal virtual void EarlyUpdate()
115115

116116
}
117117

118+
/// <summary>
119+
/// Invoked by NetworkManager at the end of its PreUpdate
120+
/// </summary>
121+
internal virtual void PreUpdate()
122+
{
123+
124+
}
125+
118126
/// <summary>
119127
/// Invoked by NetworkManager during PostLateUpdate
120128
/// </summary>

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,29 @@ internal override void EarlyUpdate()
963963
{
964964
;
965965
}
966+
}
967+
}
968+
969+
internal override void PreUpdate()
970+
{
971+
if (m_Driver.IsCreated)
972+
{
973+
if (m_ProtocolType == ProtocolType.RelayUnityTransport && m_Driver.GetRelayConnectionStatus() == RelayConnectionStatus.AllocationInvalid)
974+
{
975+
Debug.LogError("Transport failure! Relay allocation needs to be recreated, and NetworkManager restarted. " +
976+
"Use NetworkManager.OnTransportFailure to be notified of such events programmatically.");
977+
978+
InvokeOnTransportEvent(NetcodeNetworkEvent.TransportFailure, 0, default, m_RealTimeProvider.RealTimeSinceStartup);
979+
return;
980+
}
966981

967982
while (ProcessEvent() && m_Driver.IsCreated)
968983
{
969984
;
970985
}
971986
}
987+
988+
base.PreUpdate();
972989
}
973990

974991
internal override void PostLateUpdate()

com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportTestHelpers.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
116116
EarlyUpdate();
117117
break;
118118
}
119+
case NetworkUpdateStage.PreUpdate:
120+
{
121+
PreUpdate();
122+
break;
123+
}
119124
case NetworkUpdateStage.PostLateUpdate:
120125
{
121126
PostLateUpdate();
@@ -135,6 +140,7 @@ public override void Initialize(NetworkManager networkManager = null)
135140
{
136141
base.Initialize(networkManager);
137142
this.RegisterNetworkUpdate(NetworkUpdateStage.EarlyUpdate);
143+
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate);
138144
this.RegisterNetworkUpdate(NetworkUpdateStage.PostLateUpdate);
139145
s_Instances.Add(this);
140146
}

0 commit comments

Comments
 (0)