Networking - Second RPC function definition is always not found.

UPDATE! I got the answer! (found it last night) but I cant answer my own question, I think it’s because this question is pending moderator approval… can someone approve my question so I can answer it myself? Thanks!

Hi there and thanks for checking out my question!

I have 2 unity projects (1 client and 1 server) who connect with eachother via Unity Networking.

In the client app there are 2 functions with RPC: AddLayer and RunCommand. Both are defined like this:

[RPC]
void AddLayer(string image) {
  Debug.Log (image);
}

[RPC]
void RunCommand(string command) {
  Debug.Log (command);
}

At first I only had RunCommand. I had to send a byte and read that it was possible so I made AddLayer which used to accept a byte. After I started calling AddLayer via RPC on the server app (to the client app) it didnt work.

So I tried making a string of image instead of byte see if that worked (just like RunCommand)

Unfortunately it still didnt work! This is the error I got both with byte and string

RPC call failed because the function 'AddLayer' does not exist in the any script attached to'Main Camera'
  • This error appears on the server and not in the client’s console!

  • The function AddLayer IS present (the error must be wrong)

  • Another thing to note is that RunCommand just works fine without any issues, before and after AddLayer was added.

I call AddLayer like this (on the server):

public void SendImageLayer(NetworkPlayer client, byte[] img) {
	networkView.RPC ("AddLayer", client, "test");
}

Please ignore the fact that SendImageLayer accepts a byte, as I said earlier I changed it to a string to see if byte was the problem.

The bottom line is that it seems that only the first RPC method works.
I’m a little bit out of ideas here, if anyone knows the answer to this little mystery I would be so happy!

I run Unity 5.0.2f1 on Mac OS X

Thanks!

I figured it out!
The fix was quite astonishing actually, I’m glad I put it aside for a while and didnt try to get it working for hours.

What fixed it was that I had to make a dummy RPC definition on the server project. Just as simple as this:

[RPC]
void AddLayer(byte[] image) {
}

On the client project I have real code in the AddLayer function.
Even though AddLayer on the server never gets called (because I only call this on client project) Unity still requires both projects to have the same definition.

So why did RunCommand work? Because it happened to be that I had the same RunCommand function on the server project!

This is not documented by unity as far as I can tell, but I think that’s mainly because most users use the same project with Networking and not 2 separated projects (I think my needs are quite specific) Anyway I hope I helped someone with this answer!