Search Unity

Problem serializing NetworkPlayer in OSNV?

Discussion in 'Multiplayer' started by Shizen, Feb 14, 2013.

  1. Shizen

    Shizen

    Joined:
    Dec 31, 2012
    Posts:
    14
    I just started learning Unity's networking framework a few days ago, and I've encountered a few anomalies for which I haven't been able to locate explanations. I was hoping someone here might be able to set me straight ;). My question for this post has to do with serializing a NetworkPlayer in OSNV.

    So, I have an object which maintains a list of players, Network Instantiated on the server. Its NetworkView is observing the script, OSNV gets called properly, it runs in the background, State Synch is set to RDC. First client connects, everything works fine. When the second client connects, however, the NetworkPlayer of the first player is partially blanked out from the perspective of the second client, and the NetworkPlayer of the second player is partially blanked out from the perspective of the first client. They are read "blanked out" in OSNV. All NetworkPlayer look fine on the server, however :(.

    I've looked at this for a while now, and my best guess is that the problem stems from the fact that both clients are connecting to the server from the same machine (in fact, all three are on the same machine). Their NetworkPlayer indexes are distinct and consistant, but the guid, port and IPAddress fields of the NetworkPlayer not "native" to the client in question are empty/0. I have tried sending the NetworkPlayer data via RPC, with the same results...

    Am I doing something wrong, or is this expected behavior?
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    That is normal behaviour. The NetworkPlayer object contains connection specific info.
    The NetworkPlayer object itself will not change though. Each client has it's own object.
     
  3. Shizen

    Shizen

    Joined:
    Dec 31, 2012
    Posts:
    14
    Something about the wording of your reply is confusing me. NetworkPlayer is a class (actually I think it's a struct). Each client is assigned an instance of NetworkPlayer which the Unity networking system uses to identify and route messages to (as I understand it). I haven't really investigated Network.connections, but just in thinking about it, I assume Network.connections stores all the active connections (actually endpoints) to that environment/app. On the server, this would be all the clients connected to it, but on each client it would only be itself and the server. Which could also be why I'm seeing this behavior, because Unity internally bases all NetworkPlayer objects on its local Network.connections table, looking them up by index. That would imply that everything is routed through server behind the scenes, regardless of the implied implementation of things like RPC(...RPCMode.Others) when called from a client. Hrmm...

    Anyway, your statement about the NetworkPlayer object not changing confuses me. Each client has its own NetworkPlayer instance. I serialize that instance via Bitstream.Serialize (which claims to handle NetworkPlayer instances), but the NetworkPlayer instance I "unpack" on the other side of the pipe is missing several pieces of data. I'm just trying to figure out why.