Hi there, thanks so much for creating an example project, that will help greatly with finding the reason.
I haven't had a chance to look at it yet, but it does follow this template right: https://fish-networking.gitbook.io/docs/manual/guides/creating-bug-reports#sample-project
#ObserverRpc hash X registered multiple times error
12 messages · Page 1 of 1 (latest)
I see this is using version 3.11.18, would you be able to confirm this is happening in the latest version?
@winter jolt Sorry I had to blow up your message. The package you provided had Pro files in it.
Original:
Hi, I've recently run into a strange error relating to RPCs and inheriting from NetworkBehaviour. Whenever I enter play mode, I get the following error:
ObserverRpc hash 1 registered multiple times. First registration by System.RuntimeType. New registration by ChildClass.
I have managed to replicate the error in a fresh project (2022.3.14f1) with a fresh install of FN 3.11.18R Pro. I've attached this repro project. Here's a rough rundown of the situation:
I have 2 classes; ParentClass, which inherits from NetworkBehaviour, and ChildClass which inherits from ParentClass.
ParentClass is as follows:
using FishNet.Object;
using FishNet.Connection;
public class ParentClass : NetworkBehaviour
{
[TargetRpc]
[ObserversRpc]
public void ParentRPC(NetworkConnection conn)
{
}
}
ChildClass:
using FishNet.Connection;
using FishNet.Object;
public class ChildClass : ParentClass
{
[ObserversRpc]
public void ChildRPC(NetworkConnection conn)
{
}
}
I have this ChildClass component (and a NetworkObject) attached to a GameObject in a scene. Aside from this GameObject, and the NetworkManager, the scene is empty.
Entering play mode consistently gives the error above.
Interestingly, if you remove any of the Rpc tags from either of the methods, the error doesn't occur. If you attach just the ParentClass component instead of the ChildClass, the error doesn't occur.
Let me know if you need any more info,
Thank you!.```
Ah sorry! My bad. I've now reproduced this on 4.3.0 and I get a similar error: ObserversRpc key 1 has already been added for ChildClass on Object. I've created a sample project following the template and attached it. Cheers 🙂
Is it safe to assume you deleted FN before updating? nevermind, replicated
I believe I see the issue. codegen starts on the child class and counts RPCs upward to get its hash number.
Im guessing this is being read as 1 rpc when its actually 2 cs [TargetRpc] [ObserversRpc] public void ParentRPC(NetworkConnection conn)
yep thats what was happening
@winter jolt The fix is to find this method...
internal uint GetRpcCount(TypeDefinition typeDef)
{
uint count = 0;
foreach (MethodDefinition methodDef in typeDef.Methods)
{
foreach (CustomAttribute customAttribute in methodDef.CustomAttributes)
{
RpcType rpcType = base.GetClass<AttributeHelper>().GetRpcAttributeType(customAttribute);
if (rpcType != RpcType.None)
{
count++;
break;
}
}
}
return count;
}```
and replace it with this (just remove the break;)
internal uint GetRpcCount(TypeDefinition typeDef)
{
uint count = 0;
foreach (MethodDefinition methodDef in typeDef.Methods)
{
foreach (CustomAttribute customAttribute in methodDef.CustomAttributes)
{
RpcType rpcType = base.GetClass<AttributeHelper>().GetRpcAttributeType(customAttribute);
if (rpcType != RpcType.None)
count++;
}
}
return count;
}```
That did the trick! I can also confirm this works in 3.11.18. Thanks @honest glade for the quick and helpful support!