networkView.viewID what exactly is it for?

Hello,

I’m new to unity, I thought it was going to be a piece of cake, but now I’m thinking I bit off more than I can chew.

I’m trying to make an authoritative server game, where the client players send their desired movements to the server, then the server sends back to all clients, the actual movement position information.

When a client connects to the server, the server uses RPC calls to create the player objects on all of the clients. In the player script Awake() function, I create a networkView object, and attach it to the player object dynamically for synchronization. So all player clients are doing this as each new player connects to the game server, so everybody can see everybody else.

The problem I have is when the player client wants to move, the client tries to do RPC call to the server using the dynamically attached networkView, to send the desired movements, but the RPC call fails, giving an error on the SERVER (not the client), that the server cant find the networkViewID.

My code didnt print this error, so I guess it must be code deep inside unity that printed it when it received the RPC message from a client, and tried to match it up with a corresponding networkviewID on the server, when it could not, it printed the error?

I’m just wondering how unity works… does object “A” on all clients and server have the same networkViewID, and object “B” on all clients and servers have the same ID (but different ID from “A”)?

If so, how do networkView objects that are instantiated on clients and server know which ID to assign themselves so they all match up when this is being done on different computers over the network? Is this done automatically by unity, or do I have to send the ID myself to all networkView objects?? But I cant talk to the objects to tell them which ID to use, since I dont know the networkID in the first place, since that is apparently needed to talk to the networkView objects! Its like trying to ask someone their name, but you need their name in order to ask them. So that cant be how it works.

My problem is that at first, the player object has no networkView on it. After the object is created, the script on player object dynamically attaches a networkView. Since this is done on all clients, and on the server almost at the same time, how will they all know to assign the same ID to the same objects, so that they can RPC each other?

Also I read somewhere that the “owner ID” is always zero???

Sorry I’m new to unity, and trying to figure it all out. Can anyone give me the inside scoop on all this?

Thanks
rough

To simplify: Owner ID is the machine instantiating objects. NetworkViewID is object identification number over the network.
Yes, an obiect A must have the same networkViewID on all the machines (server, clients); an object B must have the same networkViewID on all the machines (server, clients) but different from A.
You can do following:

  • when player connected to the server, generate a networkViewID (on the server)
  • when send spawn RPC from server to all machines, provide the value of generated networkViewID as parameter
  • Instantiate (spawn) the object on all machines and then overwrite the values of networkViewID of instantiated object with the value received from server.