- Home /
networkView.viewID returning same for server and client
Hi, I'm sure I'm misunderstanding something here.
I'm trying to create one player for each client, and server.
So I have an empty GameObject called "ScriptsContainer" which has these following scripts:
ServerScript.js //enabled = Network.isServer;
ClientScript.js //enabled = true;
Instantiator.js //will create Player objects (Spheres)
Now, in ClientScript, I have this RPC Call:
if(!Network.isServer)
{
networkView.RPC("createPlayerSphere",RPCMode.All,networkView.viewID);
}
I'm passing networkView.viewID
as an argument because I'm trying to set the networkView's ID accordingly, to set one owner per sphere.
In Instantiator.js, the RPC is defined as this:
@RPC
function createPlayerSphere(networkviewid:NetworkViewID)
{
var the_networkview = NetworkView.Find(networkviewid);
var the_owner = thenetworkview.owner;
mySphere = Instantiate(this.SpherePrefab);
mySphere.name="sphere ["+networkviewid.ToString()+"]";
mySphere.GetComponent(NetworkView).viewID=networkviewid;
}
So it is supposed to set the new object's networkview.viewid accordingly.
It works, but the problem is, both server and client send the same NetworkViewID, which looks like this:
SceneID: 1 Level Prefix : 0
What am I doing wrong? Should I use Network.Instantiate();
Instead of -RPC- Instantiate? If I do that, I cannot remove the object when the player disconnects..
Answer by Dave-Carlile · Jul 18, 2013 at 12:53 PM
If you're going to manually assign view IDs you need to allocate them using Network.AllocateViewID.
Answer by Jamora · Jul 18, 2013 at 01:19 PM
You should use Network.Instantiate, because it's easier. After players disconnect, OnPlayerDisconnected will be called on the server and all objects instantiated by that player can be removed, as shown in the documentation.