My name is Esteban Maldonado and I’m a developer advocate for Unity. My job is to spread the word about Unity Gaming Services and create new educational material so developers can get started with the tools for their own multiplayer development journey.
One of those solutions is Netcode for GameObjects (NGO), a first-party, mid-level networking library built for the Unity game engine. A netcode solution is essential in any multiplayer development project.
One of the responsibilities of a developer advocate at Unity is to create sample games that showcase our tools, and an NGO sample was assigned to me – Galactic Kittens.
However, although I’ve had my good share of professional gigs in the games industry, I personally have little experience making multiplayer games – so this was going to prove to be not just a learning opportunity for developers who use the sample, but also a learning experience for me making the game in the first place.
Together with my team, we fleshed out the concept of Galactic Kittens – the difficulty level of the sample, the basic mechanics, the character abilities (which were later removed), and more.
In order to tackle this sample game project, I joined forces with the talented team at Bromio in order to make this sample game come to life with polished art assets, music and SFX, and programming support. Our combined goal was to provide developers with a simple, beginner-friendly introduction to building a multiplayer game in Unity with Netcode for GameObjects.
In this blog, I’ll cover the development journey for Galactic Kittens, from prototype to stable release, and how you can leverage this sample to start your own multiplayer project.
Before I dive into its development, here’s a quick overview of our new sample game Galactic Kittens. This sample is a 2D co-op space adventure designed to help you learn some basics of multiplayer networking.
The sample is meant to teach you necessary techniques to get started with multiplayer development, such as:
While I didn’t have too much experience making multiplayer games, Unity does have many public resources to help users get started with using NGO.
With these resources, I started very simply by familiarizing myself with basic network concepts and terminology, using our Unity Multiplayer documentation. Next, I followed the Hello World project tutorials and studied available bitesize samples to start getting some results.
After some trial and error, I was able to make a simple base prototype from scratch.
At this point, there was no custom lobby, no real UI, no real connection management – you get the picture. The prototype was just two equal ships (with three Hit Points each) that moved around the screen and shot a cube bullet when you pressed the spacebar. It was just enough to show object spawning and movement synchronization across clients.
It was a start, but I knew that Bromio would help us reach the finish line and turn this into a workable sample.
After my initial progress, I started working with Bromio on fleshing out the prototype into something more production-ready. Like me, they did not have much experience making multiplayer games, but they took on the challenge and helped us reach our goal.
In order to work more efficiently, we broke down the game into isolated components to start development in parallel – with artists working on assets and programmers working on the core logic of the game.
Here’s a peak at the evolution of the art style in Galactic Kittens.
Meanwhile, Bromio’s main developer and I were discovering fun and challenging aspects of making Galactic Kittens into a functioning game sample.
One of the biggest challenges in development was connection management and character selection. We had to store the data of the characters in separate ScriptableObject files, which you will see when you download the project.
These files contain the necessary information about each space explorer, including which sprites (player and ship) to show on the UI and the prefabs that should be spawned for each player once the gameplay scene starts.
On the character selection screen, a big challenge was to make sure to acknowledge the event of a client disconnecting and to handle that event through the UI.
We decided that users should not be able to pick the same character, in order to show how developers could actually do this in their own games. (It's actually easier to let players pick the same character since there’s no additional restriction.)
The next challenge for connection management was the event of players disconnecting in the middle of a game session. This meant not only that the game had to adapt to players leaving, but also had to block other players from entering while a game is in session. We decided to make the connection manager only allow for new connections to come in while the host instance is on the character selection screen. This is not a one-size-fits-all solution – other games may allow for players to join late in an ongoing session, while other games may not – it’s up to developers to decide what’s best for their experience.
We wanted to keep gameplay simple, with no complex AI or fancy behavior logic for the enemies or meteorites that players see. This way, we could provide a full game sample without taking away focus from showing users how to use the NGO library.
As such, there are two main types of enemies and one meteorite obstacle:
Both enemies choose a random movement pattern, while the Space Shooter enemy is the only one that actually shoots back enemy lasers. Please refer to our developer guide for more information on how these enemies are built and how you can add your own logic.
By the time we worked on the boss battle, all of the lessons learned from implementing the game’s lobby, player spaceship behavior, and simple enemies helped us to quickly build the final boss battle experience.
One particular challenge was timing the warning alarm that you hear and see before the boss enters. In the end, we sent events with client and server RPCs in order to signal that the regular play experience was over and the final boss battle was about to begin.
The behavior of the boss is structured as a finite state machine (FSM) that randomly selects which set of attacks to throw at the connected players. To do this, we used a C# class called BossController, which handles the transition from one boss state to another. Check the developer guide for information about the code behind this battle, and how you can add your own boss states.
The #1 resource that helped us succeed in our mission to build this sample game was joining the Unity Multiplayer Networking Discord server and asking questions to the community. Here, we were able to actually speak with other developers who are making multiplayer games and also speak with Unity multiplayer service creators. The collective pool of knowledge was more than enough to help us reach the finish line.
Working at Unity means I get to collaborate alongside networking savvy people who work hard to develop helpful resources and documentation that’s designed to assist everyone get started with multiplayer development. The Unity multiplayer documentation site came in handy many times – from familiarizing myself with basic networking terminology to dealing with latency to actually coding with NGO.
We're definitely excited about Galactic Kittens. We’d like for you, and future NGO users, to use this sample as a step in the right direction toward your multiplayer learning journey. Please feel free to reach out in the Discord server or forums to ask questions or provide feedback and suggestions.
One of the things I’m eager to learn is how to add object pooling to a multiplayer game sample. This is the technique that lets you pre-allocate the necessary memory for objects that get spawned repeatedly during a game session. In an earlier experiment, I tried this technique in an offline Unity project and it can definitely make an improvement to your game’s run-time efficiency. We’ve applied this technique to Boss Room and other UGS samples as well.
If you’re starting out on your own multiplayer journey, then there are a lot of resources that my team at Unity provides to help make it easier for you.
I would recommend starting at the Netcode for GameObjects page, where you can familiarize yourself with the package. Next, you can explore NGO through the Galactic Kittens sample or take small steps with bitesize samples.
Once you’re on your journey, I recommend joining the Unity Multiplayer Networking Discord server and checking out the forums. And, if you feel like Galactic Kittens is too simple or not enough of a challenge, I would definitely encourage you to check out Boss Room, which is a complete 3D sample game that takes NGO development to a production-ready level.
For taking your game online, Unity Gaming Services can help you even further – whether you’re looking to add the Lobby or Matchmaker services, voice and text chat with Vivox, or even hosting solutions like the P2P Relay service or Game Server Hosting. Happy creating!
To find out more about recent trends and the future of multiplayer, read the 2022 Unity Multiplayer Report, which aggregates the results of over 1,500 survey responses across the US, UK, Japan, and Korea.