Skip to content

Commit 07f48e7

Browse files
committed
Update docs
1 parent 7da97ce commit 07f48e7

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

com.unity.netcode.gameobjects/Documentation~/command-line-arguments.md

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
11
# WORK IN PROGRESS
22
# Command line arguments
33

4-
You can use [command line arguments](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html) to configure some aspects of your game. With dedicated server you can use command line arguments to override default ip address and port.
4+
You can use [command line arguments](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html) to configure certain aspects of your game at launch. This is especially useful for dedicated server builds, where arguments let you override default network settings such as the IP address and port.
55

6+
## Using Command Line Arguments
67

8+
When launching a standalone build (for example, a headless dedicated server), you can supply custom arguments to modify runtime behavior.
79

8-
Something you can use if you want to launch a standalone build (particulary usefull for dedicated server builds)
9-
(include all known command line )
10-
-port
11-
-ip (TODO) check where is the endpoint, I may only need to assign it with no convert
10+
Available arguments:
11+
- -port
12+
- -ip
1213

14+
Unity provides built-in parsing for standard arguments, and you can extend this behavior by adding your own.
1315

14-
we provided port and ip and you can add your own command line args and retieve them in the CommanLineOptions class and grab them in your project by using GetArgs
16+
---
1517

16-
[!Note]
17-
Adding a command line argument requires that you retrieve and set that command line argument
18+
## Custom Arguments
1819

20+
You can define additional custom command line arguments and retrieve them through the `CommandLineOptions` class.
21+
Use `GetArgs()` in your project code to collect and process these values.
1922

23+
[!NOTE]
24+
Adding a custom command line argument requires you to explicitly retrieve and handle it in your implementation.
2025

26+
---
2127

22-
You can force override the command line arguments by using the optional boolean argument in SetConnectionData(string, ushort, string, bool) from UnityTransport.
28+
## Example: Reading Command Line Arguments
29+
```
30+
private const string k_OverrideArg = "-argName";
31+
32+
private bool ParseCommandLineOptions(out string command)
33+
{
34+
if (CommandLineOptions.Instance.GetArg(k_OverrideArg) is string argValue)
35+
{
36+
command = argValue;
37+
return true;
38+
}
39+
command = default;
40+
return false;
41+
}
42+
```
43+
44+
Usage example:
45+
46+
```
47+
if (ParseCommandLineOptions(out var command))
48+
{
49+
// Your logic here
50+
}
51+
```
52+
53+
---
54+
55+
## Overriding Connection Data
56+
57+
If you want to ignore the connection **port** provided through command line arguments, you can override it by using the optional `forceOverride` parameter in:
58+
59+
```
60+
UnityTransport.SetConnectionData(string ip, ushort port, string listenAddress, bool forceOverride);
61+
```
62+
63+
Setting `forceOverride` to `true` ensures that the values you pass to `SetConnectionData` override any values specified via command line arguments.
2364

24-
~~~~

0 commit comments

Comments
 (0)