Skip to content

Commit fb59e49

Browse files
authored
fix: require Server/ClientRpcParams to be last parameters in RPC methods (backport) (#1721)
1 parent 08d6d77 commit fb59e49

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2525
- Fixed error when serializing ConnectionApprovalMessage with scene management disabled when one or more objects is hidden via the CheckObjectVisibility delegate (#1720)
2626
- Fixed CheckObjectVisibility delegate not being properly invoked for connecting clients when Scene Management is enabled. (#1680)
2727
- Fixed NetworkList to properly call INetworkSerializable's NetworkSerialize() method (#1682)
28+
- Fixed ServerRpcParams and ClientRpcParams must be the last parameter of an RPC in order to function properly. Added a compile-time check to ensure this is the case and trigger an error if they're placed elsewhere (#1721)
2829
- Fixed FastBufferReader being created with a length of 1 if provided an input of length 0 (#1724)
2930
- Fixed The NetworkConfig's checksum hash includes the NetworkTick so that clients with a different tickrate than the server are identified and not allowed to connect (#1728)
3031
- Fixed OwnedObjects not being properly modified when using ChangeOwnership (#1731)

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,13 +942,29 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
942942
var paramDef = methodDefinition.Parameters[paramIndex];
943943
var paramType = paramDef.ParameterType;
944944
// ServerRpcParams
945-
if (paramType.FullName == CodeGenHelpers.ServerRpcParams_FullName && isServerRpc && paramIndex == paramCount - 1)
945+
if (paramType.FullName == CodeGenHelpers.ServerRpcParams_FullName)
946946
{
947+
if (paramIndex != paramCount - 1)
948+
{
949+
m_Diagnostics.AddError(methodDefinition, $"{nameof(ServerRpcParams)} must be the last parameter in a ServerRpc.");
950+
}
951+
if (!isServerRpc)
952+
{
953+
m_Diagnostics.AddError($"ClientRpcs may not accept {nameof(ServerRpcParams)} as a parameter.");
954+
}
947955
continue;
948956
}
949957
// ClientRpcParams
950-
if (paramType.FullName == CodeGenHelpers.ClientRpcParams_FullName && !isServerRpc && paramIndex == paramCount - 1)
958+
if (paramType.FullName == CodeGenHelpers.ClientRpcParams_FullName)
951959
{
960+
if (paramIndex != paramCount - 1)
961+
{
962+
m_Diagnostics.AddError(methodDefinition, $"{nameof(ClientRpcParams)} must be the last parameter in a ClientRpc.");
963+
}
964+
if (isServerRpc)
965+
{
966+
m_Diagnostics.AddError($"ServerRpcs may not accept {nameof(ClientRpcParams)} as a parameter.");
967+
}
952968
continue;
953969
}
954970

0 commit comments

Comments
 (0)