Fast multiplayer prototyping with Unity 6
Context
This year in March during the Game Developers Conference in San Francisco (GDC 2024), Unity announced a series of changes to their new editor version called Unity 6. Part of their message was the new updates to how you can make online multiplayer games. A lot of these are built to help you increase your iteration time and focus on what is mostly important to deliver a solid game, the gameplay.
Here's a link to the roadmap session. I'm starting it in the multiplayer section:
In this article I'll be showing you how you can get started using some of the new multiplayer tools that help you to automatically create a basic networked scene as a good starting point in building a multiplayer game:
Creating your Unity 6 project
So the first thing that we need to do is to install Unity 6. Thankfully this is a very straightforward and easy step, because it's essentially the same step as installing the current 2022 LTS version. In the Unity hub, click on the install button:
In the official releases section, You'll be able to access the Unity 6 preview build. Note that you may see a higher number than 6000.0.4f1
. If so, that's ok and pick the latest version:
It's over 6000!!!! ๐
Once we have the unity editor installed, it's time to create your project. This step is also not that different from creating a project using 2022 LTS. Click on the new project button:
Then choose your template. I'm going with Universal Render Pipeline (URP):
And change the editor version to Unity 6:
And lastly we'll add a project name, and connect your project to the Unity Cloud. This will be useful later. Trust me:
After this, it'll take a few minutes, but our project will be created.
Install the new Multiplayer Center
Once our new Unity 6 project is opened, head over to the windows tab and from there go to the package manager button:
From there go to "+" button on the top-left, and we'll add the first package we'll need, the Multiplayer Center:
Add it by name, and insert the following text: com.unity.multiplayer.center, and click on the Install button:
Let the editor run, and you'll see the package installed:
Quick note
โ Before we continue, I'm excited to show you what these tools can do and the value that they could bring to your future game. But I'd like to acknowledge the fact that at the time of writing this article, most of these solutions are in experimental stage. I recommend using them for something like prototypes or in a game jam, since they'll very likely go through big development changes.โ
Please read Unity's online manual about experimental packages. Even they do not recommend using them for production games.
But with that out of the way, let's continue! ๐
Choose your tools with the Multiplayer Center
Now that we have the Multiplayer Center installed, you can access this new tool by going into the Windows tab and clicking on the Multiplayer Center button:
You'll now see this new cool window pop up:
This is the starting point of our journey to make a multiplayer game! We can go ahead and choose what kind of game we'd like to make. I'm going to choose an adventure game for now:
And let's now choose a maximum amount of 8 concurrent players. After that, click on the Get Recommendations button that you see below:
The tool will add more options for you to choose. The Game Specifications section on the top-left corner are the settings we just set before.
Not gonna lie, that's a lot of options, so let's discuss the main ones.
wow those are a lot of settings! ๐ฐ
Netcode Solution
The netcode solution is the layer of code that helps to gather necessary data about what a player is doing that'll be relevant to other players during the networked session. We'll be using Netcode for GameObjects, since we'll be working with regular GameObjects, and not entities from Unity DOTS (Data Oriented Technology Stack).
Multiplayer Tools
Leave this option enabled as it includes good tools to help you debug your game!
Hosting Model
The hosting model refers to the connection structure of how your players are going to communicate with each other through the devices that they'll be playing your game. The window is recommending that we use the Dedicated Server model, but let's change this option. Dedicated server can be a good option, but one that takes longer to setup, and is usually a more expensive one. The biggest advantage of having dedicated servers is that you can setup fleets of server across many regions of the world. So your game can have a much wider reach.
But we're just starting here, so let's use the client hosted model which is easiest to setup, and good for multiplayer beginners.
This means that one of the players participating in the networked session is going to own or be the host or all other players that connect to the session. That owner or host is going to act as the server that contains the state of the world and communicates it to all other connected players or clients. Clients on the other hand place their inputs and send requests to the server to alter the state of the world.
Here's a quick diagram of that might look like for 8 players. The one in the center is the owner or host of the game:
For more information about hosting models (known as network topologies), feel free to check out the multiplayer documentation on this topic.
Recommended Multiplayer packages
For today, we don't to use the Voice/Text chat feature. But it's perfectly ok if you'd like to try it out!
We'll use the other 3 options in order to create the networked scene shown at the beginning.
After the choices are confirmed, click on the install button:
This will install all of the packages necessary to build our game. It might take a while, since it'll be installing many of them in a row.
Automatically setup your networked scene
After all packages are installed, the window will switch to the Quickstart
tab. And again, many options are shown. But let's visit these sections as needed:
Adding basic setup
At the moment, our Unity scene is still at its simplest state. Let's add the necessary GameObjects to make this a starter multiplayer scene. Click on the Add basic setup
button:
Let's set the multiplayer center window aside for a bit, and go to your scene hierarchy now. You'll see that some new objects have been added:
To briefly explain the purpose of these 2 new objects:
Network Manager: This game object holds the network manager component that gets included with Netcode for GameObjects. This is the main entry point for starting or joining a networked session.
Temporary UI: This is a temporary UI to interact with the network manager game object
Save your scene, and then play it. We get this menu that lets you choose between starting a networked session as a host (client and server), or if we'd like to join or connect an existing networked session as a client:
Click on the start host button, and you'll see that a movable Cube will be automatically instantiated for you. This is already a network scene working in its simplest form. You can move the cube using the W,A,S,D keys.
Testing with Multiplayer Play Mode
So we have a moving cube that's part of our multiplayer game and it's the player avatar, awesome! But now let's make this even more interesting. We'll go ahead and add another player using the play mode tools.
Go back into the multiplayer center window and let's open the Multiplayer Play Mode tools by clicking on the Open Window button:
This tool lets us create what is basically a copy of the project to help us simulate like if there's another device playing that will connect to the networked session. Click on the Player 2 checkbox to enable a simulated 2nd player:
It'll take a little while, but definitely helpful once you use it!
Another window will now open in game mode open. We'll play the game from both windows:
Play the main editor window and click on the start host button. Now click on the start client window on the second screen, and you'll see another cube spawn. Move the cubes in each window and see that their position is synchronized!
And just like that, you now can play and move around to objects that are synchronized across a networked session. And all assets needed to get to this point we're added automatically for you.
Automatically take your game online
Now here comes what I think is the coolest part about these new tools. Remember at the beginning when we were creating the unity project, and I mentioned that we have to connect our editor project to the unity cloud? This is when this option will come in handy. We are now going to change our current prototype to not just work in your own device, but to be able to connect online!
Adding the Quick Start Widgets
Go back into the Multiplayer Center window, and inside of the Connecting Players section, click on the Add Quick Start Widget Sample
button:
We get this pop up. Click on the Import TMP Essentials
button. These are necessary packages in order to render the new UI that's going to show up in the scene:
Go back into the scene hierarchy and you'll notice that inside of the UI game object that was added earlier, there's a new child object that holds a new UI that is currently rendered on top of the older UI:
To disable the old UI click on the game object called Image
, and disable it from the object inspector. Save your scene again, to update your 2nd player window.
And at this point, when we play the game and create a networked session, we'll be doing this over the internet! This is thanks to the Multiplayer Services package we installed earlier.
One more cool widget!
Let's add one more widget to help us. Inside of the scene hierarchy, but without clicking on any game objects, right-click on the following option:
woah that's a long path ๐
What we're adding here is a UI element that will show the list of online sessions that are available:
Since it creates the UI at the top-left corner, I'll move it down a bit on the transform component (-240.0 on the Y-axis):
Save your scene again to update your 2nd player window. And now play the game from the main editor window, and click on the Quick Create button:
After the session is created and your cube shows up, go to the 2nd player window and click on the Refresh button:
You'll now see the session you created on the main editor window show up. Click on it, and then click on the Join button below, near the bottom-left corner:
And here we go! You're now playing in the same computer, but over the internet!
We've now reached the point that we established at the beginning of this article!, and now you have a good starting point to continue building your multiplayer game.
Share the networked scene!
As a surprise, one more thing I wanted to show is that once you build the the project to the platform of your choice (PC, Mac, etc.), or share your Unity project with a friend or a co-worker, they'll be able to join you (or vice-versa) on an active session and play the networked scene with you! Here are 2 computers connected over the internet playing together:
2 devices already playing over the internet, automatically!
Lessons learned
Making multiplayer games is even easier for Unity users now, and a lot of the less fun boilerplate elements of a prototype are already automatically handled and added for you.
Even with all these tools, making online games is still tough, and will require lots of trial and error to make a more complete game.
Please let me know what you think!
What do you think of these new tools, and do encourage you to try making a multiplayer game?
What's your first thought for improving them?
What genre immediately comes to mind for making your multiplayer game?
๐๐๐ Happy building! ๐๐๐
Subscribe to my newsletter
Read articles from Esteban Maldonado directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Esteban Maldonado
Esteban Maldonado
๐๐พ Hello! ๐๐พ My name is Esteban and I love video games and learning about making games. I'm sharing here my progress as I build up my skills and learn new technologies.