Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ceaa7e7
Moving comand line options to unity transport
noellie-velez Oct 27, 2025
b94624c
Updating project version (can be reverted)
noellie-velez Oct 27, 2025
31b985d
Disable build scenes + add CommandLineOverrideTest
noellie-velez Oct 27, 2025
65ae1d7
Reset NetworkManager and UnityTransport
noellie-velez Oct 27, 2025
7f9eeca
Investigate DedicatedServer.Arguments.Port null
noellie-velez Oct 27, 2025
d03b1f6
Merge branch 'develop-2.0.0' into fix/v2.x/add-flag-dedicated-server-…
noellie-velez Oct 29, 2025
3c33a86
Merge branch 'develop-2.0.0' into fix/v2.x/add-flag-dedicated-server-…
noellie-velez Oct 29, 2025
6615c9a
Remove non editor upgrade changes
noellie-velez Oct 29, 2025
542aaa8
Package update
noellie-velez Oct 29, 2025
13960e3
Moving comand line options to unity transport
noellie-velez Oct 27, 2025
fda6999
Clean up
noellie-velez Oct 29, 2025
adb5132
Reset/delete files to exlude
noellie-velez Nov 3, 2025
41928fd
Editor version minimalproject + Example projects
noellie-velez Nov 3, 2025
0e7c72b
Editor upgrade testproject 6000.61f1 (latest LTS)
noellie-velez Nov 3, 2025
1f1070c
Merge branch 'develop-2.0.0' into chore/v2.x/testproject-editor-upgra…
noellie-velez Nov 3, 2025
ee3a3ec
Merge branch 'develop-2.0.0' into fix/v2.x/add-flag-dedicated-server-…
noellie-velez Nov 3, 2025
3576a44
reset manifest
noellie-velez Nov 3, 2025
45b04ca
Merge branch 'chore/v2.x/testproject-editor-upgrade-6000.0.60f1' into…
noellie-velez Nov 3, 2025
40c2d2b
Rename forceOverrideCommandLineArgs
noellie-velez Nov 3, 2025
c48d446
Remove Override and ParseArgs, add flag to overide
noellie-velez Nov 3, 2025
78c1d4c
Remove logs
noellie-velez Nov 3, 2025
8d5f45d
Merge branch 'develop-2.0.0' into fix/v2.x/add-flag-dedicated-server-…
noellie-velez Nov 3, 2025
370b459
Address review comments TODO cleanup
noellie-velez Nov 3, 2025
05b794c
Revert files
noellie-velez Nov 4, 2025
ec6d03b
Fix unknown arg when not dedicated server profile
noellie-velez Nov 4, 2025
9efec5f
Merge branch 'develop-2.0.0' into fix/v2.x/add-flag-dedicated-server-…
noellie-velez Nov 6, 2025
4f12176
Revert "Revert files" + test project
noellie-velez Nov 6, 2025
b5c104d
Creating a command line option class + singleton
noellie-velez Nov 6, 2025
8724c37
Remove DGS and PortOverrideCLI testing files
noellie-velez Nov 6, 2025
200ea59
Remove redundant ushort cast
noellie-velez Nov 6, 2025
f19a7b9
Fix maxnumberplayers documentation Note
noellie-velez Nov 6, 2025
783a78d
Adding documentation to public API
noellie-velez Nov 6, 2025
e7e5d1b
WIP documentation
noellie-velez Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if( m_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPl
}
```

> [!NOTE]
> [!NOTE]
> In connection approval delegate, Netcode for GameObjects doesn't support sending anything more than a Boolean back.

<!-- Commenting this out until we can get external code references working
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# WORK IN PROGRESS
# Command line arguments

You can use [command line arguments](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html) to configure some aspects of your game but sometimes it is needed to force another value.


You can force override the command line arguments by using the optional boolean argument in SetConnectionData(string, ushort, string, bool) from UnityTransport
11 changes: 6 additions & 5 deletions com.unity.netcode.gameobjects/Documentation~/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

Configure your Netcode for GameObjects project.

| **Topic** | **Description** |
| :------------------------------ | :------------------------------- |
| **[Configuring connections](configure-connections.md)** | Configure connections in your project. |
| **[Transports](advanced-topics/transports.md)**| Transport layers establish communication between your application and different hosts in a network. |
| **[Relay](relay/relay.md)**| Use Unity Relay with Netcode for GameObjects. |
| **Topic** | **Description** |
|:--------------------------------------------------------|:----------------------------------------------------------------------------------------------------|
| **[Configuring connections](configure-connections.md)** | Configure connections in your project. |
| **[Transports](advanced-topics/transports.md)** | Transport layers establish communication between your application and different hosts in a network. |
| **[Relay](relay/relay.md)** | Use Unity Relay with Netcode for GameObjects. |
| **[Command line arguments](command-line-arguments.md)** | Use command line arguments. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Unity.Netcode
{
/// <summary>
/// This class contains a list of the application instance domain's command line arguments that
/// are used when entering PlayMode or the build is executed.
/// </summary>
public class CommandLineOptions
{
/// <summary>
/// Command Line Options Singleton
/// </summary>
public static CommandLineOptions Instance { get; private set; } = null!;

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void RuntimeInitializeOnLoad() => Instance = new CommandLineOptions();

// Contains the current application instance domain's command line arguments
internal static List<string> CommandLineArguments = new List<string>();

// Invoked upon application start
[RuntimeInitializeOnLoadMethod]
private static void ParseCommandLineArguments()
{
// Get all the command line arguments to be parsed later and/or modified
// prior to being parsed (for testing purposes).
CommandLineArguments = new List<string>(Environment.GetCommandLineArgs());
}

/// <summary>
/// Returns the value of an argument or null if there the argument is not present
/// </summary>
/// <param name="arg">The name of the argument</param>
public string GetArg(string arg)
{
var argIndex = CommandLineArguments.IndexOf(arg);
if (argIndex >= 0 && argIndex < CommandLineArguments.Count - 1)
{
return CommandLineArguments[argIndex + 1];
}
return null;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -976,19 +976,6 @@ public NetworkPrefabHandler PrefabHandler
internal NetworkConnectionManager ConnectionManager = new NetworkConnectionManager();
internal NetworkMessageManager MessageManager = null;

internal struct Override<T>
{
private T m_Value;
public bool Overidden { get; private set; }
internal T Value
{
get { return Overidden ? m_Value : default(T); }
set { Overidden = true; m_Value = value; }
}
};

internal Override<ushort> PortOverride;

/// <summary>
/// Determines if the NetworkManager's GameObject is parented under another GameObject and
/// notifies the user that this is not allowed for the NetworkManager.
Expand Down Expand Up @@ -1168,8 +1155,6 @@ internal void Initialize(bool server)
return;
}

ParseCommandLineOptions();

if (NetworkConfig.NetworkTransport == null)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
Expand Down Expand Up @@ -1740,40 +1725,6 @@ private void OnDestroy()
#endif
}

// Command line options
private const string k_OverridePortArg = "-port";

private string GetArg(string[] commandLineArgs, string arg)
{
var argIndex = Array.IndexOf(commandLineArgs, arg);
if (argIndex >= 0 && argIndex < commandLineArgs.Length - 1)
{
return commandLineArgs[argIndex + 1];
}

return null;
}

private void ParseArg<T>(string arg, ref Override<T> value)
{
if (GetArg(Environment.GetCommandLineArgs(), arg) is string argValue)
{
value.Value = (T)Convert.ChangeType(argValue, typeof(T));
}
}

private void ParseCommandLineOptions()
{
#if UNITY_SERVER && UNITY_DEDICATED_SERVER_ARGUMENTS_PRESENT
if ( UnityEngine.DedicatedServer.Arguments.Port != null)
{
PortOverride.Value = (ushort)UnityEngine.DedicatedServer.Arguments.Port;
}
#else
ParseArg(k_OverridePortArg, ref PortOverride);
#endif
}

#if UNITY_EDITOR
internal static INetworkManagerHelper NetworkManagerHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,43 @@ public void SetClientRelayData(string ipAddress, ushort port, byte[] allocationI
SetRelayServerData(ipAddress, port, allocationId, key, connectionData, hostConnectionData, isSecure);
}

// Command line options
private const string k_OverridePortArg = "-port";

private bool ParseCommandLineOptions(out ushort port)
{
#if UNITY_SERVER && UNITY_DEDICATED_SERVER_ARGUMENTS_PRESENT
if (UnityEngine.DedicatedServer.Arguments.Port != null)
{
port = (ushort)UnityEngine.DedicatedServer.Arguments.Port;
return true;
}
#else
if (CommandLineOptions.Instance.GetArg(k_OverridePortArg) is string argValue)
{
port = (ushort)Convert.ChangeType(argValue, typeof(ushort));
return true;
}
#endif
port = default;
return false;
}

/// <summary>
/// Sets IP and Port information. This will be ignored if using the Unity Relay and you should call <see cref="SetRelayServerData"/>
/// </summary>
/// <param name="ipv4Address">The remote IP address (despite the name, can be an IPv6 address or a domain name).</param>
/// <param name="port">The remote port to connect to.</param>
/// <param name="listenAddress">The address the server is going to listen on.</param>
public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null)
/// <param name="forceOverrideCommandLineArgs">When true, any command line arguments will be ignored.</param>
public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null, bool forceOverrideCommandLineArgs = false)
{
m_HasForcedConnectionData = forceOverrideCommandLineArgs;
if (!forceOverrideCommandLineArgs && ParseCommandLineOptions(out var commandLinePort))
{
port = commandLinePort;
}

ConnectionData = new ConnectionAddressData
{
Address = ipv4Address,
Expand Down Expand Up @@ -1566,6 +1595,11 @@ protected override string GetDisconnectEventMessage(DisconnectEvents disconnectE
return m_UnityTransportNotificationHandler.GetDisconnectEventMessage(disconnectEvent);
}

/// <summary>
/// This is set in <see cref="SetConnectionData(string, ushort, string, bool)"/>
/// </summary>
private bool m_HasForcedConnectionData;

/// <summary>
/// Initializes the transport
/// </summary>
Expand All @@ -1579,12 +1613,16 @@ public override void Initialize(NetworkManager networkManager = null)
return;
}
#endif

m_NetworkManager = networkManager;

if (m_NetworkManager && m_NetworkManager.PortOverride.Overidden)
//If the port doesn't have a forced value and is set by a command line option, override it.
if (!m_HasForcedConnectionData && ParseCommandLineOptions(out var port))
{
ConnectionData.Port = m_NetworkManager.PortOverride.Value;
if (m_NetworkManager?.LogLevel <= LogLevel.Developer)
{
Debug.Log($"The port is set by a command line option. Using following connection data: {ConnectionData.Address}:{port}");
}
ConnectionData.Port = port;
}

m_RealTimeProvider = m_NetworkManager ? m_NetworkManager.RealTimeProvider : new RealTimeProvider();
Expand Down
15 changes: 12 additions & 3 deletions testproject/Assets/Scripts/testproject.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
"Unity.Services.Authentication",
"Unity.Services.Core",
"Unity.Services.Relay",
"Unity.Addressables.Editor"
"Unity.Addressables.Editor",
"Unity.Networking.Transport"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.services.relay",
Expand All @@ -22,5 +30,6 @@
"expression": "",
"define": "TESTPROJECT_USE_ADDRESSABLES"
}
]
}
],
"noEngineReferences": false
}
5 changes: 5 additions & 0 deletions testproject/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ PlayerSettings:
androidStartInFullscreen: 1
androidRenderOutsideSafeArea: 1
androidUseSwappy: 1
androidDisplayOptions: 1
androidBlitType: 0
androidResizeableActivity: 0
androidDefaultWindowWidth: 1920
Expand All @@ -86,6 +87,7 @@ PlayerSettings:
muteOtherAudioSources: 0
Prepare IOS For Recording: 0
Force IOS Speakers When Recording: 0
audioSpatialExperience: 0
deferSystemGesturesMode: 0
hideHomeButton: 0
submitAnalytics: 1
Expand Down Expand Up @@ -271,6 +273,9 @@ PlayerSettings:
AndroidBuildApkPerCpuArchitecture: 0
AndroidTVCompatibility: 0
AndroidIsGame: 1
androidAppCategory: 3
useAndroidAppCategory: 1
androidAppCategoryOther:
AndroidEnableTango: 0
androidEnableBanner: 1
androidUseLowAccuracyLocation: 0
Expand Down
Loading