Unity: Testing Multiplayer in Multiple Editor Instances

If you work on a multiplayer project, you’ll sooner or later come to the point where you want to play, test and debug your game locally by running multiple instances of it.

UE4 multiplayer options
In Unreal Engine 4 this is simply done by increasing the player counter.

It just so happens to be that Unity currently doesn’t support this feature out-of-the-box. Many critical comments and curses (while people are raising their fists to the sky in anger) I’ve read in forums and on social media about that, but don’t fret: I’ve got you covered.

Normally, when you try to start an already opened project in Unity Hub you get a message like this:

Unity warning about opened project
Yes, I know!

So the solution for that is starting the Unity project again without starting the same project. “Madness! He’s gone mad!”, you may think, but there is an easy way to do this: Links.

Links are a feature provided by your operating system, as in Windows, MacOS or Linux. It’s a link to another folder, just like the shortcut in Windows. There are two types of links:

  • Soft links (Symlinks): Leads to the location. Can be spread across multiple drives and file systems.
  • Hard links (Junctions): Leads to the actual files/folders on the drive. Works even if the source folder is moved/deleted, but has to be on the same file system.

Thus, links make a program believe that this is an actual folder (with the identical content of another one). So let’s trick Unity by creating a “new” project with the contents of our game project.

Open a terminal window in your OS (use the “cmd” tool in Windows, not the powershell) and navigate to the folder above your project folder. The following commands will create a new folder and soft links for the essential stuff.

Windows:

mkdir ClonedProject
cd ClonedProject
mklink /D Assets ..\ActualProject\Assets
mklink /D ProjectSettings ..\ActualProject\ProjectSettings
mklink /D Packages ..\ActualProject\Packages

Linux/MacOS:

mkdir ClonedProject
cd ClonedProject
ln -s ../ActualProject/Assets Assets
ln -s ../ActualProject/ProjectSettings ProjectSettings
ln -s ../ActualProject/Packages Packages

In normal cases soft links should do the trick. If you want to create hard links instead, use “/J” instead of “/D” on Windows or remove the “-s” on Linux/MacOS.

Linking the three folders “Assets”, “ProjectSettings” and “Packages” is enough. The other files and folders will be created and used by Unity as an individual project. It’s similar to what you want to check in to your version control (git, SVN, Perforce, etc.).

All that’s left is to add the cloned project via Unity Hub and open it. After all the importing stuff is done, you should have two Unity instances of the same game project. Whenever you change something, the other instance will reload/compile as soon as it comes into focus.

Sources:

Leave a comment

Your email address will not be published. Required fields are marked *