Poor documentation for NetworkPlayer

So yeah, here’s what has caused me a lot of headaches in my current project – I’ve utilized NetworkPlayer on occasion for network code handling CTF flags, deployable turrets, and more. Hope this thread can help bring the issue to light because I had to dig deep in the forums to learn about it.

What the documentation doesn’t mention is that NetworkPlayer is only really useful to the server… the clients don’t have a clue as to what NetworkPlayer is which. To the client, everything is reported as 0 – this default behavior can actually mislead you because if it’s just 1 client connected to the server, things can actually work out. It’s when there’s several people connected (when the client thinks there are several NetworkPlayers with the same ID) that problems can occur.

larus also points this out in this thread: http://forum.unity3d.com/threads/8568-Why-don-t-the-network-views-have-owners-assigned?highlight=networkplayer+server+correct+client

It’s not a big deal when this is known – viewID can go a long way and messages sent directly to another player just need to be relayed via RPC through the server (who can direct the RPC to the correct player when provided with an owned viewID), but the documentation doesn’t even hint at this behavior. I’m currently in the process of rewriting a lot of my network code to account for this, but not being aware of this has caused me some major headaches trying to debug my network code (especially since it usually worked fine when I tested it myself, but caused problems when I held live playtests with a group of fans).

I guess theoretically (haven’t tested), you might be able to manually have the server send out the correct NetworkPlayer info to each client so that they could use it with some confidence, but I haven’t had a reason to do this (yet) – I just use viewID more.

there is no “correct network player info” technically cause it changes constantly on the server as users login and logout again actually.

Also network player should work if you just use it as its meant ie as RPC Target for example instead of using all / other modes. But what you NEVER must do is use its int value. that would be a serious error and will, due to what I mentioned in the first sentence, be granted to fuck up.
Also do not cache the network players (ie don’t hold references to them!).
You must request them as needed or send them through as needed in RPCs if the other side would need to send a 1 : 1 response