Networking between two different projects

Hello,

the problem is this: we want to split client and server of our game in different projects, but we’re not able to make RPC work.
On the server I have a prefab of an object with attached a script (the networkView is attached), whose methods I want to invoke from the clients.
When the client connects I call Network.Instantiate on the server to instantiate the object and here I get the first error: “MissingReferenceException: The variable controllerPrefab of ‘NetworkManager’ doesn’t exist anymore”.
Moreover on the client I get another error when I try to call a method on the object, because it doesn’t exist.

2 Answers

2

I tried something similar. First of all you can’t completely seperate the server from the client. Both instances need the exact same prefab(s) (asset instance ID) or Network.Instantiate wouldn’t work.

Next thing is, which is quite annoying, both sides need all RPC functions you want to use. Even when you have functions that are only called on the server, the client needs to implement them as well or the call fails. The functions only have to exist, they don’t need to do the same thing, they could even be empty as long as the signature matches.

Thank you for the help. Since I have very little experience in Unity I hope you can clarify these two points: 1) I understand what you mean by saying both clients and server must have the same prefabs, but what do you mean with "asset instance ID"? 2) In your opinion is it better to implement something like this using Network (even if Unity Network is evidently not designed for something of this kind) or it would be better to use something else (I'm actually thinking at implementing this with C# socket)? Again thanks a lot for your help!

Ok thank you very much you've been very helpful, especially for the trick of using different scenes for client and server, I think that we will try that way.

How do you debug if you have the client and server in different scenes and not different projects? That means you can only ever debug one of them, because the other one has to be a build?

Ok I need again your help if possible :slight_smile:
I have set up two different scenes, one for the client and the other for the server.
So now there is a single project containing the prefab of the object that I want to share beetween the hosts.
The server calls Network.Instantiate when starting (precisely inside the OnServerInitialized method) and when the client connects we receive this error: “Network.Instantiate on the receiving client failed because the asset couldn’t be found in the project”.
It seems the same problem that we had before. Now the prefab should really be exact the same.