Hi, I wanted to run some thoughts by the Unity community here to get some input and figure out what my best options would be.
To set some background, I have some professional software development experience, but still relatively new to gamedev, I have agreed to, on the side, help out a friend with networking for a Unity game they have been working on. As a rough overview of the game style, the game has 4 players in an arena fighting.
To start off with all this I have been trying to decide what networking solution to go with. I have been reading up on these forums, saw the big pros/cons thread, and have generally been looking over feature lists and reviews and whatever else I could find to try and decide. And it seems like the options are basically to either go with one of the fully integrated high level options like Photon or Mirror, or else go with a more custom solution using LiteNetLib, DarkRift Networking 2, or even just c# sockets.
At first glance I suspect that Photon could do the trick, and maybe building from the ground up it would be the definitive answer, but my concern is that with a pre existing game I might be better off trying to tailor a custom solution to the existing architecture. Does anyone here have experience trying to incorporate Photon into a pre-existing codebase?
And secondly, for those that have tried a more low level option, how much difficulty does that tend to add? I feel I have a pretty solid grasp on the game networking concepts from sites like gafferongames and the like, and although I’m sure it would be more complicated I don’t think it would be insurmountably so, and the added difficulty may be worth it to have more control over exactly how I handle things (as well as separating from the Photon cloud, opening up my options there). Is my intuition way off base there?
And finally, any other general thoughts on adding networking to a game that doesn’t currently have it?
I can’t help with the Photon question, but generally all the high level networking API’s require you to build your game around them rather than bolting them on to the way you’ve already built your game. That can mean a significant redesign of many of your game’s systems, depending on what you’ve already got.
As far as using a low level option, most likely you’ll want to create your own higher level networking systems on top of it (for anything but the simplest of games at least). Developing those high level systems means a lot of playing with byte arrays and a lot of attention to detail, but when you have that set up it can be tailor made for your game, or can build it more general purpose like other existing high level API’s while addressing needs you have which may not have been met, or giving you intimate knowledge of the networking system which you lack when you use someone else’s.
As far as a general thought on adding networking to a game, a couple big issues are what computer “owns” certain data, what computers which don’t own the data need that data, and how that data is updated. As an example, take an inventory system. You’d probably want the server to actually control the player’s inventory to reduce cheating, but clients need to display that inventory to the player, and need to be able to tell the server to make changes to the inventory. Consumable items need to regularly be used from the inventory and be updated to the player’s client.
You’ll find there’s lots of systems like that you need to deal with which are straight forward in a single player game, but get complicated in a multiplayer game. Do you send an to the client every time the inventory is updated? In some games that is probably a good approach, but what if your game includes machine guns, where you may be updating the the inventory 15 times per second? What happens if the player is firing the machine gun and says to drop its ammo on the ground from inventory even though the ammo should have run out by the time the server receives the command to drop the ammo? There’s lots of things like this you end up thinking about.
Thanks! Yeah I decided to tackle building a custom networking solution. It will give me more experience, allow me to tailor the approach to the specific game, and I won’t need to deal with adapting to a specific networking model.
And good general networking advice, will definitely keep those things in mind. I have been slowly working through the problem these last few weeks and figuring out data ownership and how to structure things to handle all the various edge cases has definitely been one of the tricky parts.
If you’re going to build your own networking system, I’d suggest starting with thinking about what higher level features you want to include. It might be helpful to try out some of the ready made systems to get an idea how they work, so you can see what you like and what you don’t. My project started on Unet for example, and there were things I really liked about it, and some things I didn’t like. So when I moved my project to my own network system I borrowed concepts I liked, and adding things I thought were missing.