RPC: Connecting two existing NetworkViews

Hello!

Let me explain in detail what am I doing. I’ve created a server project with one scene. On that scene I’ve added empty game object and called it Server. On this object I added NetworkView script my GameServer/Server.cs script, where Network.InitializeServer is called and OnPlayerConnected/Disconnected events are handled.

Next, I created project for client application. In a new scene I’ve added empty game object and called it Server, with NetworkView and GameClient/Server.cs script on it. Now I want to call GameServer/Server’s methods from client using RPC. But they have different NetworkID’s, and I can’t change the NetworkID of NeworkView in the editor.

So the question is how do I connect two different pre-existing objects, created offline in the editor, to make RPC calls between them?

My game is very simple one. It don’t use advanced physics or needs state syncs at all, only two RPC calls making a move and a callback from server to sync field state after any of players makes move. And two RPC more to join/start new game and to quit.

Are you sure you want a completely separate project to do this?? Because that doesn’t seem like a very wise route, could you elaborate on what exactly you’re trying to accomplish here?

It should not really matter whether the clients and servers are using the same project or not. It would not be weird to have a server that has no 3D, just a GUI, or even no rendering at all and only physics and database.

I believe that the question is relevant when even when the server and the client use the same project. Imagine an open world multi-player. Alice Bob and Charlie are playing the game, Alice is hosting, Bob and Charlie are clients.

Alice, Bob and Charlie are exploring three different areas of the world, they all have their own creatures, NPCs, inventories, quests and treasures. Alice’s server has the three areas loaded at once, even though only one is layered for rendering on her main camera. Each area has NetworkView objects that were created with Network.Instanciate when Bob and Charlie joined, some are destroyed and others created during play. Until now, everything’s fine.

Problem: Charlie is coming back to Bob’s area. Remember, it’s an open world, there’s no loading scene. Charlie loads the terrain (that’s static, no network sync). But what about the creatures and the rest? The Server can send to Charlie a list of creatures to spawn (there are ten giant spiders in the forest) with a RPC, but these creatures are already existing on Alice’s and Bob’s computers, and their NetworkViews are already connected. How do Charlie’s spiders start following the orders from Alice’s server?

I have not found anywhere in the documentation how to connect NetworkViews. I’ve looked under Network, NetworkView, NetworkViewID, NetworkPlayer, nothing. It may not be possible.

The only solution that I am seeing now is to use buffered Remote Procedure Calls and using one NetworkView.group per area. As soon as Charlie enters Bob’s area, Charlie suddenly receives all the RPCs that have been buffered while he was gone. Charlie’s computer has a lot of catching up to do: as every door opened by Bob, every monster killed and every chest looted is fast-forwarded in a single frame. This should work. Things that have been Network.Instantiated between Alice and Bob have been queued as RPCs so Charlie will receive them. Indeed, Network.Instantiate is a buffered RPC, this is written there: Unity - Scripting API: Network.Instantiate .