diff --git a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs
index a963af18b..3e79855b4 100644
--- a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs
+++ b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs
@@ -797,11 +797,6 @@ public static bool ProcessMethodsValidateFunction(MethodReference md)
public static bool ProcessMethodsValidateParameters(MethodReference md, CustomAttribute ca)
{
bool isTargetRpc = ca.AttributeType.FullName == Weaver.TargetRpcType.FullName;
- if (isTargetRpc && md.Parameters.Count == 0)
- {
- Weaver.Error($"{md.Name} must have NetworkConnection as the first parameter", md);
- return false;
- }
for (int i = 0; i < md.Parameters.Count; ++i)
{
@@ -816,27 +811,18 @@ public static bool ProcessMethodsValidateParameters(MethodReference md, CustomAt
Weaver.Error($"{md.Name} cannot have optional parameters", md);
return false;
}
- // TargetRPC is an exception to this rule and can have a NetworkConnection as first parameter
+
bool isFirstParam = i == 0;
+ bool isNetworkConnection = p.ParameterType.FullName == Weaver.NetworkConnectionType.FullName;
- if (isTargetRpc && isFirstParam)
+ // TargetRPC is an exception to this rule and can have a NetworkConnection as first parameter
+ if (isNetworkConnection && !(isTargetRpc && isFirstParam))
{
- if (p.ParameterType.FullName != Weaver.NetworkConnectionType.FullName)
- {
- Weaver.Error($"{md.Name} must have NetworkConnection as the first parameter", md);
- return false;
- }
+ Weaver.Error($"{md.Name} has invalid parameter {p}. Cannot pass NeworkConnections", md);
+ return false;
}
- else
- {
- if (p.ParameterType.FullName == Weaver.NetworkConnectionType.FullName)
- {
- Weaver.Error($"{md.Name} has invalid parameter {p}. Cannot pass NeworkConnections", md);
- return false;
- }
- }
-
}
+
return true;
}
diff --git a/Assets/Mirror/Tests/Editor/Weaver/.WeaverTests.csproj b/Assets/Mirror/Tests/Editor/Weaver/.WeaverTests.csproj
index 6ebeaebbb..566884407 100644
--- a/Assets/Mirror/Tests/Editor/Weaver/.WeaverTests.csproj
+++ b/Assets/Mirror/Tests/Editor/Weaver/.WeaverTests.csproj
@@ -214,7 +214,8 @@
-
+
+
diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests.cs
index 3552d5ed0..a55a199f2 100644
--- a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests.cs
+++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests.cs
@@ -25,16 +25,21 @@ public void ErrorWhenTargetRpcIsStatic()
}
[Test]
- public void ErrorWhenTargetRpcIsMissingNetworkConnection()
+ public void TargetRpcCanSkipNetworkConnection()
{
- Assert.That(weaverErrors, Contains.Item("TargetRpcMethod must have NetworkConnection as the first parameter " +
- "(at System.Void WeaverTargetRpcTests.ErrorWhenTargetRpcIsMissingNetworkConnection.ErrorWhenTargetRpcIsMissingNetworkConnection::TargetRpcMethod())"));
+ Assert.That(weaverErrors, Is.Empty);
+ }
+
+ [Test]
+ public void TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection()
+ {
+ Assert.That(weaverErrors, Is.Empty);
}
[Test]
public void ErrorWhenNetworkConnectionIsNotTheFirstParameter()
{
- Assert.That(weaverErrors, Contains.Item("TargetRpcMethod must have NetworkConnection as the first parameter " +
+ Assert.That(weaverErrors, Contains.Item($"TargetRpcMethod has invalid parameter nc. Cannot pass NeworkConnections " +
"(at System.Void WeaverTargetRpcTests.ErrorWhenNetworkConnectionIsNotTheFirstParameter.ErrorWhenNetworkConnectionIsNotTheFirstParameter::TargetRpcMethod(System.Int32,Mirror.NetworkConnection))"));
}
}
diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/ErrorWhenTargetRpcIsMissingNetworkConnection.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/ErrorWhenTargetRpcIsMissingNetworkConnection.cs
deleted file mode 100644
index 758ecbcfa..000000000
--- a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/ErrorWhenTargetRpcIsMissingNetworkConnection.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using Mirror;
-
-namespace WeaverTargetRpcTests.ErrorWhenTargetRpcIsMissingNetworkConnection
-{
- class ErrorWhenTargetRpcIsMissingNetworkConnection : NetworkBehaviour
- {
- [TargetRpc]
- void TargetRpcMethod() { }
- }
-}
diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection.cs
new file mode 100644
index 000000000..ca7b08ae3
--- /dev/null
+++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection.cs
@@ -0,0 +1,10 @@
+using Mirror;
+
+namespace WeaverTargetRpcTests.TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection
+{
+ class TargetRpcCanHaveOtherParametersWhileSkipingNetworkConnection : NetworkBehaviour
+ {
+ [TargetRpc]
+ void TargetRpcMethod(int usefulNumber) { }
+ }
+}
diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanSkipNetworkConnection.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanSkipNetworkConnection.cs
new file mode 100644
index 000000000..ec0858925
--- /dev/null
+++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests~/TargetRpcCanSkipNetworkConnection.cs
@@ -0,0 +1,10 @@
+using Mirror;
+
+namespace WeaverTargetRpcTests.TargetRpcCanSkipNetworkConnection
+{
+ class TargetRpcCanSkipNetworkConnection : NetworkBehaviour
+ {
+ [TargetRpc]
+ void TargetRpcMethod() { }
+ }
+}