|
1 | 1 | # WORK IN PROGRESS |
2 | 2 | # Command line arguments |
3 | 3 |
|
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. |
5 | 5 |
|
| 6 | +## Using Command Line Arguments |
6 | 7 |
|
| 8 | +When launching a standalone build (for example, a headless dedicated server), you can supply custom arguments to modify runtime behavior. |
7 | 9 |
|
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 |
12 | 13 |
|
| 14 | +Unity provides built-in parsing for standard arguments, and you can extend this behavior by adding your own. |
13 | 15 |
|
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 | +--- |
15 | 17 |
|
16 | | -[!Note] |
17 | | -Adding a command line argument requires that you retrieve and set that command line argument |
| 18 | +## Custom Arguments |
18 | 19 |
|
| 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. |
19 | 22 |
|
| 23 | +[!NOTE] |
| 24 | +Adding a custom command line argument requires you to explicitly retrieve and handle it in your implementation. |
20 | 25 |
|
| 26 | +--- |
21 | 27 |
|
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. |
23 | 64 |
|
24 | | -~~~~ |
|
0 commit comments