Welcome to my first official book review!
*cue streamers and fireworks*
Unity Multiplayer Games by Alan Stagner, published by Packt Publishing is a really interesting and relevant read for anyone interested in multiplayer game programming. Even if you are not the biggest Unity buff, the book explores a lot of great concepts that are critical to designing and implementing multiplayer video games.
Read on to find out what the books covers, some pitfalls, and even play the Pong game the book has you make…..
Unity Multiplayer Games by Alan Stagner, published by Packt Publishing, covers a variety of paradigms to use for creating multiplayer games in Unity. Starting from basic UDP communication, the book progressively builds up through cloud-hosted game servers, matchmaking, chat clients, event systems, stat databases, server-side entity interpolation and hit detection. All done in Unity C#. It is an extremely powerful and detailed book that will have you building all kinds of cool multiplayer projects right from Chapter 1!
Anyone familiar with Unity 3 or 4 and basic C# can pick up this book and learn some very awesome skills that are relevant to the games industry. As someone who is currently just getting started in game development professionally, I can attest the topics covered in this book are very relevant. With the way the industry is moving progressively to an “always-online, always-connected” state, these skills are critical to have if you want to stand out while looking for a programming or design job.
So lets start the review of the book in detail. Right from chapter 1, you start with UDP client to client design and implementation using the native Unity networking API. The book does a great job explaining why this primitive technique would be used over others, and does so for every type thereafter. This is critical because there is no silver bullet for online video games. Every game is different and has different requirements for gameplay. Some games take turns, other games do not need super low latency communication, while other games are high-paced and are much better with each second of delay shaved off. The book explains these trade offs well. In this case, client/client (peer to peer) communication is nice due to low latency but has a myriad of inherent problems such as the ability of the host client being able to change data on his end and cheating.
The book, from the start, teaches you how to implement not only just simple networking in Unity but also various techniques that greatly enhance them. For example, for native Unity networking, using Unity’s Master Server allows the developer to allow players to host their own games and “post listings”. So another player can load up their game, ask “who can I play with”, and click to join the other player hosting. Once you have this running and can see other people host their own games using your own code and seeing that game pop up on your game’s server list, it feels fantastic. This is, in its most primitive format, how AAA video games do it! Very rarely, if ever anymore, do you need to ask someone directly “whats your IP and port so I can play?”
There are some issues following the first tutorial though I must point out, as great as it is. First of all, it doesn’t define a lot of terminology. Sometimes it does and its nice, but other times it doesn’t and it expects you to know. Such as “serialize and deserialize”. It shows you how to use them though, and beginners can kind of gleam its purpose. It also employs screenshots to show how it should look or how Unity should be setup, but they are few and far between. In places where they should be, they aren’t, and in places where they shouldn’t be, they are. It is excusable in some cases because the book is not meant as an introduction to Unity or C# itself. The tutorial should not be expected to guide you every tiny step of the way when you’re expected to have this knowledge already. However, in cases where specific networking-related settings are being done in the editor, it can be confusing.
For example, I believe I found a typo or just a lack of clarification during the Pong example:
By default, network views will serialize the attached transform… Now, add a Network View to one of your paddles, drag the panel component attached to the Paddle into the Observed slot, and make it a prefab by dragging it into your Project pane.
I am not the most seasoned Unity developer out there, but which exact panel component are we dragging here? There are 6 in total at this point, and I have no idea which one it is. Trial and error can be tricky because you’re following along and maybe there is an error in your code if you’re not just copying/pasting from the download included with the book. This will lead you to dismissing a component that is correct. It turned out to be the script component itself, but it took me several hours of playing around to figure that out. This is a perfect case where even a small, sliced screenshot would’ve been a huge help as I’ve capture above.
I completed the networked Pong tutorial and it came out very well. I love these kinds of tutorials because you can build upon them however you want. You could be audacious and add 4 player Pong co-op or change it to a 2 player game of classic Breakout very easily. I opted for adding the Master Server functionality explain earlier in the book and made it so anyone can host a game and have players join them without any knowledge of ports/ips.
Moving on, the book explains various external APIs for Unity that are arguably better suited for most games than the native libraries. It will teach you how to do online versions of a star-collecting game, a real-time strategy game, and part of how a first person shooter game would handle movement and hit detection.
However I found it odd that the book does not go into detail on how like the first Pong tutorial. For the RTS game for example, it just goes through code. It doesn’t explain anything about how to hook things up in Unity. I haven’t completed the RTS example yet, but I’ve been toying with it and while the “creativity” is open ended here, some might not ever get a working example if they can’t hook up the components and objects properly or see perhaps how its supposed to look functionally.
There are other little nice things though. As I mentioned before you can download the code from the book’s website. The book explains a little multi-threaded programming such as mutex locking and unlocking which is a huge concept for professional programmers, especially for networked games where nearly everything is working in parallel in a stateless game. It even explains how to do some database tracking of player stats, IDs, and logins through JSON parsing which was very nice to see.
And the best part, in my opinion, was seeing a very relevant and crucial explanation to entity interpolation on the server side of games such as Left 4 Dead, Team Fortress 2, and the upcoming Titanfall game (currently in open beta) which all employ Valve’s source engine. This was handled very well and there are even little diagrams to explain the conceptual parts.It then went on to explain how to implement this in C# Unity. Really good stuff and I highly highly recommend the read because of it.
So, there you have it. Unity Multiplayer Games by Alan Stagner is a great read. The only other issue with the book is that it just concludes after that point. It doesn’t do any kind of overall summary or some easily-readable comparison chart of each of the techniques discussed, like a pros and cons chart. But all things said and done, the stuff I said were issues are just minor. The book accomplishes what it sets out to do: explore various relevant networking techniques for video games and lay a great foundation for you to get your multiplayer project started and up off the ground.
Unity Multiplayer Games by Alan Stagner
- Highly relevant topics for game design today and the future
- Good explanations of why each method would be used over the others
- Demonstrates how to get each method up and running in Unity C#, even if a little barebones
- Awesome Pong tutorial acts as a foundation for any kind of project
- Do not need Unity Pro
- Not many screenshots or proper details to the tutorials
- Doesn’t always explain terminology
- Arguably poor code writing ethic such as naming conventions, typos
- Lack of a overall conclusion
Who for: Anyone interested in network programming for video games, especially in Unity.
Requirements: To follow the tutorials, some Unity and C# experience. Otherwise, its still a great read to gleam interesting facts.
Hi, Anthony. Great book review. Thanks!
My pleasure! ^_^