- Home /
Networking between projects: how to send ViewIDs?
Closest similar issue I can see is here, but it doesn't address my problem: http://answers.unity3d.com/questions/579459/networking-between-two-different-projects.html
I want to have a project that runs a dedicated server for our game (which lives in another project). The dedicated server project is a separate project because it has to be as lean as possible in terms of CPU and Memory use, needs none of the assets from the game, and runs in headless mode.
Both projects have an object called "server" with a networkView attached. Both projects have an object called "client" with a networkView attached. Both projects have a player prefab with a networkView attached, which is instantiated as players load in.
The client and server can connect. The catch-22 is that neither side can send RPCs to one another because the ViewIDs don't match, and I don't know how to tell either side what the correct ViewIDs are without sending an RPC. OnPlayerConnected and OnConnectedToServer do not transmit this information afaik.
The errors I get are (with generic variables):
-View ID xxx not found during lookup. Strange behaviour may occur
-Could't invoke RPC function 'yyy' because the networkView 'xxx' doesn't exist
Is there a way to communicate ViewIDs between separate client and server projects?
Answer by Unit-E · Jul 08, 2014 at 10:23 PM
Found a workaround with help with another developer. The problem is that Unity seems to assume that all networking will be done within a single project, even though the engine gives you the option to start dedicated and headless servers.
The workaround is to delete all NetworkViews in your project except for one, which should be attached to an indestructible gameobject. Unity will assign a "scene" NetworkViewID to this NetworkView of "0" (sometimes 1), and as long as there is a matching NetworkViewID of 0 (or 1) on both server and client, you can generate the other NetworkViews you need with AddComponent and then pass the initial RPCs needed to establish your network through the object with the NetworkViewID #0(1) (Unity will complain about a network object going missing, but it allows you to continue). You have to do it this way because you can't allocate NetworkViewIDs from the server without RPCs (for which you need a working and matching NetworkView), and you can't manually set the NetworkViewID scene number (for no apparent reason).
Probably the best method of doing this is to create a unitypackage from a prefab of this network object, which may allow you to avoid the warning as well if everything is identical. I also had to include a bit of code to re-assign new NetworkViewIDs on objects if newly-allocated IDs matched "#0" (Unity will still allocate IDs that are built into the scene).
Your answer
Follow this Question
Related Questions
Networking: RPC To Specific Player? 1 Answer
Network RCP between client server projects 0 Answers
Is server the sender of RPC? 0 Answers
Unity networking tutorial? 6 Answers
How do I change networkView ownership of a Rigidbody by clicking on it? 1 Answer