No Behaviour for Incoming RPC (UNet Pitfalls #2)

Some problems are so intractable that you almost despair on them, like the one with the RPC error message that haunted me for two months. It was even more stubborn than the one I wrote about in my last post. Imagine you are working happily on your multiplayer game and out of nowhere you get an error that says “Found no behaviour for incoming ClientRPC …”. In this case, I really did not change anything in that part of the code and the error just popped up.

The whole error message looked like this:

Found no behaviour for incoming [ClientRpcRpcUpdateRemoveButton] on PlayerInfo(Clone) (UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances [netId=1].
RPC error message in Detail. Click to enlarge!
Searching for it with Google showed up nothing useful. It seems that not many people have managed to generate this error so far. Unfortunately, I had no clue what had triggered this error. It appeared in the lobby of my game where I had not been working on at all. Debugging did not help, so I tried the usual things when you don’t know where to start:

  • Restarting Unity.
  • Reimporting all assets.
  • Deleting the Library folder.
  • Going back to the last version in my repository and adding the latest changes step by step. The error did not reappear after I had finished which did not really make me confident that it would stay that way. And it did not. It was there again when I restarted Unity.
  • Updating Unity to the latest version (5.5.1). It helped, the error appeared only once, and disappeared again for three weeks. But then suddenly it was here again.

So what helped?

I started removing the offensive RPCs and Commands from the PlayerInfo script, but with every one I removed a new error appeared for another RPC method. This made me wonder if UNet did not somehow mix up these RPC methods. Only then did I remember that I had duplicated the PlayerInfo script from Unity’s Network Lobby example package.  I had moved it into my own project’s namespace so that I had the two following classes:

namespace Prototype.NetworkLobby
{
  public class LobbyPlayer : NetworkLobbyPlayer
  {
    [...]
  }
}

and

namespace MyProject.Networking
{
  public class LobbyPlayer : NetworkLobbyPlayer
  {
    [...]
  }
}

Just renaming the old class in namespace Prototype.NetworkLobby made the errors go away!

Finding the right RPC

My guess is that the UNet code generator cannot distinguish between different namespaces. It may just be random which of the two classes with the same name is used to look up the RPC methods. If the wrong one is selected it is no surprise that it cannot be found as a component of the target game object.

The lesson to be learned from this is quite simple: when using UNet, do not use classes with identical names in your project, even if they are in different namespaces. This probably applies only to classes derived from NetworkBehaviour, but better be careful.

0 0 votes
Article Rating
Abonnieren
Benachrichtige mich bei
0 Comments
Inline Feedbacks
View all comments
0
Was denkst Du? Bitte hinterlasse einen Kommentar!x