Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why don't the network views have owners assigned?

Discussion in 'Multiplayer' started by nafonso, Jan 29, 2008.

  1. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    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:
    So I tried to do the following:
    Code (csharp):
    1. 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):
    Code (csharp):
    1. if (playerIdentifier == localPlayer) {
    2.     Debug.Log("Enabling user input as this is the local player");
    3.     // W are doing client prediction and thus enable the controller script + user input processing
    4.     instantiatedPlayer.GetComponent(ThirdPersonController).enabled = true;
    5.     instantiatedPlayer.GetComponent(ThirdPersonController).getUserInput = true;
    6.     // Enable input network synchronization (server gets input)
    7.     instantiatedPlayer.GetComponent(NetworkController).enabled = true;
    8.     instantiatedPlayer.SendMessage("SetOwnership", playerIdentifier);
    9.     return;
    10.     // Initialize player on server
    11. }
    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?

    Regards,
    Afonso
     
  2. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    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.

    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.

    It only sets the view ID. The owner is determined internally on the server. You can't actually set this property yourself.
     
  3. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    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.
     
  4. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    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.
     
  5. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    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! :p Sorry for doubting :oops:
     
  6. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    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:

    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: