I’m having real issues getting my head around unity’s built-in networking.
This post is a mix of my experiences and questions I have.
My main problem so far has been finding a clean way to implement networking, I have tried various different structures and still haven’t found a good one, mabye i’m just thinking about it all the wrong way.
I started off writing game, server and client logic all into one piece of code. That quickly became messy and difficult to handle (lots of “ifServer(do this) else (do this)” and short-circuits for the server as you can’t RPC yourself…).
The next re-write, I split the code into server and client. But that meant replicating the game logic. Didn’t seem right.
The current re-write i’m working on I split into server, client and seperate gameLogic. This seems better but there’s still a lot of replication and special cases that i’m finding frustrating.
Problems I’ve encountered :
-
Server doesn’t seem to call “OnPlayerConnected” for itself and doesn’t appear in the network.connections list.
-
Can’t RPC yourself (Used in the case where you are the server. I would have to call functions directly in the Client logic which again leads to spaghetti code!)
-
NetworkViewID isn’t serializable, you can send it through an RPC directly, but in my case I tried to create a serializable class containing all player Information so I can send all player info in bulk or with a full game state package (eg, to a new connecting client).
-
Can’t RPC byte : not really problem as you can send a byte[ ]. It just means an extra command to pack/unpack from the array. (just don’t understand why it’s not supported…I use a byte for playerID’s, which is another thing, Unity seems to apply it’s own unique ID’s to players (Server is 0) but with no way of accessing that info. It appears in the console with network debugging enabled)
If anyone has any advice on how to seperate server/client/game logic in a clean way I would be eternally grateful!
(Or am I even going about this the right way?)
Owen