Skip to content

Commit 233cbd7

Browse files
feat: Allow reliable sends to go over maximum payload size (#2081)
* feat: Allow reliable sends to go over maximum payload size
1 parent a3e3e52 commit 233cbd7

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
99

1010
### Changed
1111

12+
- When using `UnityTransport`, _reliable_ payloads are now allowed to exceed the configured 'Max Payload Size'. Unreliable payloads remain bounded by this setting. (#2081)
13+
1214
### Fixed
1315

1416
- Fixed issue where NetworkAnimator was not removing its subscription from OnClientConnectedCallback when despawned during the shutdown sequence. (#2074)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ public int MaxPacketQueueSize
158158
set => m_MaxPacketQueueSize = value;
159159
}
160160

161-
[Tooltip("The maximum size of a payload that can be handled by the transport.")]
161+
[Tooltip("The maximum size of an unreliable payload that can be handled by the transport.")]
162162
[SerializeField]
163163
private int m_MaxPayloadSize = InitialMaxPayloadSize;
164164

165-
/// <summary>The maximum size of a payload that can be handled by the transport.</summary>
165+
/// <summary>The maximum size of an unreliable payload that can be handled by the transport.</summary>
166166
public int MaxPayloadSize
167167
{
168168
get => m_MaxPayloadSize;
@@ -1148,14 +1148,14 @@ public override NetcodeNetworkEvent PollEvent(out ulong clientId, out ArraySegme
11481148
/// <param name="networkDelivery">The delivery type (QoS) to send data with</param>
11491149
public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
11501150
{
1151-
if (payload.Count > m_MaxPayloadSize)
1151+
var pipeline = SelectSendPipeline(networkDelivery);
1152+
1153+
if (pipeline != m_ReliableSequencedPipeline && payload.Count > m_MaxPayloadSize)
11521154
{
1153-
Debug.LogError($"Payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
1155+
Debug.LogError($"Unreliable payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
11541156
return;
11551157
}
11561158

1157-
var pipeline = SelectSendPipeline(networkDelivery);
1158-
11591159
var sendTarget = new SendTarget(clientId, pipeline);
11601160
if (!m_SendQueue.TryGetValue(sendTarget, out var queue))
11611161
{

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,5 +457,26 @@ public IEnumerator SendQueuesFlushedOnRemoteClientDisconnect([ValueSource("k_Del
457457

458458
yield return null;
459459
}
460+
461+
[UnityTest]
462+
public IEnumerator ReliablePayloadsCanBeLargerThanMaximum()
463+
{
464+
InitializeTransport(out m_Server, out m_ServerEvents);
465+
InitializeTransport(out m_Client1, out m_Client1Events);
466+
467+
m_Server.StartServer();
468+
m_Client1.StartClient();
469+
470+
yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events);
471+
472+
var payloadSize = UnityTransport.InitialMaxPayloadSize + 1;
473+
var data = new ArraySegment<byte>(new byte[payloadSize]);
474+
475+
m_Server.Send(m_Client1.ServerClientId, data, NetworkDelivery.Reliable);
476+
477+
yield return WaitForNetworkEvent(NetworkEvent.Data, m_Client1Events);
478+
479+
yield return null;
480+
}
460481
}
461482
}

0 commit comments

Comments
 (0)