Why don't the network views have owners assigned?

I was going along fine with the networking in unity, until I tried to send a RPC to a specific player.

According to the docs you can use this:
function RPC (name : string, target : NetworkPlayer, params args : object[ ]) : void
Call an Rpc function on a specific player

So I tried to do the following:

m_opponents[i].networkView.RPC("sendLines", m_opponents[i].networkView.owner, 3);

However, the owner variable is never assigned. The network view id is correct, I check, but the owner never has information about the NeworkPlayer. Am I supposed to insert the owner by hand on each object?

On the networking project that UT supplied, there is no RPC call to a specific player. The only thing that has anything to do with the owner is in the Authoritative Server, where we find the following code (AuthServerSpawnPlayer.js):

if (playerIdentifier == localPlayer) {
    Debug.Log("Enabling user input as this is the local player");
    // W are doing client prediction and thus enable the controller script + user input processing
    instantiatedPlayer.GetComponent(ThirdPersonController).enabled = true;
    instantiatedPlayer.GetComponent(ThirdPersonController).getUserInput = true;
    // Enable input network synchronization (server gets input)
    instantiatedPlayer.GetComponent(NetworkController).enabled = true;
    instantiatedPlayer.SendMessage("SetOwnership", playerIdentifier);
    // Initialize player on server

However I don't find any SetOwnership in the docs. Is it not exposed? Should I set the owner of each network view this way? I thought that by using Network.Instantiate, it would set the view ids and the owner by us. Am I wrong?


The owner property is only set on the server instance. He is the only one who actually knows who owns what. From the clients points of view everything comes from the server and he essence owns everything the client himself doesn't own. Adding the owner information to the network view so that it would propagate to all clients would add a bit of overhead to network traffic and we want to minimize that.

However I don't find any SetOwnership in the docs. Is it not exposed? Should I set the owner of each network view this way?
The SetOwnership function is received by another script in the project, its not built in. You could do something like this yourself I guess. Making the server distribute owner information to everybody with an RPC function when something is instantiated.

I thought that by using Network.Instantiate, it would set the view ids and the owner by us.
It only sets the view ID. The owner is determined internally on the server. You can't actually set this property yourself.

Hmmm that's odd, because the behaviour that I explained happens on the Server and Clients (although, I think that in the Server if I output the owner, it prints 0 and on the Client I think it gave something like -213433...., although I can't verify that right now, don't have access to Unity).

But that it is not set in the server, that I'm sure of. Unless that you meant that it only sets on the server if you do Network.Instantiate in the server, but this I also can't verify right now. I know that the network instantiate by the clients will not have the owner set in the neither Server nor Client.

Then the project I pulled must be an outdated version, because, as the screenshot wil show, only that script has a SetOwnership:

Could you please update the docs with such info for the upcoming versions? It's just because these particularities we never guess.

Well, I just did a quick test with Network.Instantiate. The server sees the clients network view with the correct player ID, the client sees the servers and other clients views with player ID 0. The client always sees the server with the player ID 0.

Its in GraduallyUpdateState.cs, I noticed the function doesn’t use the NetworkPlayer parameter any more. It must have been unnecessary in this particular case.

I just tried really fast, I’ll check more thoroughly tomorrow, but a object instantiated in the server, the server prints 0 as the owner. If that is the player ID, then it is correct! I haven’t really tried to analyze the client yet.

Well, just discovered something, spotlight for some reason doesn’t go into .cs files! :stuck_out_tongue: Sorry for doubting :sweat_smile:

I haven't looked at it really carefully, but now it seems to work (perhaps I could have done something wrong before switching to 2.0.2), although I haven't tried to see it from the client's perspective.

The only thing that looks "odd" is that when the server tries to send a RPC to himself, it fails with the following message:

Can't send RPC function because the target is not connected to the server.

But I assume that the reason is because we can't send RPCs to ourselves, from what I understood from this post http://forum.unity3d.com/viewtopic.php?t=7553&highlight=rpc+local+remote.

Thanks for clearing things up! :wink: