Create a command line helper
This section shows how to create a command line helper that launches the project outside the Unity Editor to make testing builds easier.
tip
Using a command line helper script to launch multiple instances of a game build isn’t the only way to test a multiplayer game. You can also use the Unity Editor or the Multiplayer Play Mode package.
- Right-click the Assets folder in the Projects tab, then select Create > Folder.
- Name the new folder Scripts.
- Right-click the Scripts folder you created, then select Create > C# Script.
- Name the script NetworkCommandLine.
- Right-click on NetworkManager within the Hierarchy list, then select Create Empty.
- Name the new GameObject NetworkCommandLine.
- With the
NetworkCommandLine
GameObject selected, select Add Component from the Inspector tab. - For the new component, select Scripts > Network Command Line (the
NetworkCommandLine.cs
script you created earlier). - Double-click on the NetworkCommandLine.cs script from the Project tab to open it in a text editor.
- Edit the
NetworkCommandLine.cs
script to match the following code snippet:
- Save the file, then return to the Unity Editor.
- Open the Build Settings window by selecting File > Build Settings.
- Select Player Settings….
- Beneath Settings for PC, Mac, & Linux Standalone, select Resolution and Presentation to open the section options.
- From Resolution > Fullscreen Mode, change Fullscreen Window to Windowed.
- Return to the Editor main window and save your scene.
#
Test the command line helperFollow these instructions to test that the command line helper script works.
- Select File > Build and Run.
- Create a new folder called
Build
inside your Hello World project folder. - Save As the binary “
HelloWorld
.”
Saving the project in this way causes the Unity Editor to build and launch the project in a new window. After it launches (and you see the plane), close the window you just launched.
#
Test on WindowsFor Windows you should do the following:
- Open the Command Prompt.
- Use the following command to launch the server and the client. Make sure to replace the placeholder text within the angle brackets (
< >
) for all commands.
note
You might get a UAC prompt requesting permission to run the executable. You should allow it.
Command to start the server:
Command to start the client:
To run these commands on a single line:
Here’s an example of what your command might look like when you replace the placeholder text in < >
:
important
There's no standard out stream on Windows by default, so you will need to view the Debug.log
file to see the outputs. You can find the Debug.log
files in:
Where the CompanyName
should default to DefaultCompany
for a new project and ProductName
should be equal to the project's name.
Alternatively you can change the Windows commands to create a log.txt
file in the same folder as your HelloWorld
folder.
Change the commands as follows:
Server command:
Client command:
Example (Running as a single command line):
#
Test on MacUse the following instructions if you're using MacOS:
- Open the Terminal app.
- Use the following command to launch the server and the client. Make sure to replace the placeholder text within the angle brackets (
< >
) for all commands.
Command to start the server:
Command to start the client:
To run both as a single command: