Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -499,7 +499,7 @@ private void StartDedicatedServer()
// Set the application frame rate to like 30 to reduce frame processing overhead
Application.targetFrameRate = 30;

Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}");
Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}");
Debug.Log($"[Pre-Init] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}");
// Setup your IP and port sepcific to your DGS
//unityTransport.SetConnectionData(ListenAddress, ListenPort, ListenAddress);
Expand Down Expand Up @@ -527,7 +527,7 @@ private void StartDedicatedServer()
private void ServerStarted()
{
Debug.Log("Dedicated Server Started!");
Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}");
Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}");
Debug.Log($"[Started] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}");
Debug.Log("===============================================================");
Debug.Log("[X] Exits session (Shutdown) | [ESC] Exits application instance");
Expand Down
2 changes: 2 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Deprecated

- Several APIs that were already marked `[Obsolete]` with a warning now raise a compile error instead (they are not removed yet).

### Removed

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Transports

Unity Netcode for GameObjects (Netcode) uses Unity Transport by default and supports UNet Transport (deprecated) up to Unity 2022.2 version.
Unity Netcode for GameObjects (Netcode) uses Unity Transport by default and also provides a single player transport.

## So what is a transport layer?

Expand All @@ -18,11 +18,13 @@ A transport layer can provide:

Netcode's default transport Unity Transport is an entire transport layer that you can use to add multiplayer and network features to your project with or without Netcode. Refer to the Transport [documentation](https://docs.unity3d.com/Packages/com.unity.transport@latest) for more information and how to [install](https://docs.unity3d.com/Packages/com.unity.transport@latest?subfolder=/manual/install.html).

## Unity's UNet Transport Layer API
Netcode provides a [UnityTransport](xref:Unity.Netcode.Transports.UTP.UnityTransport) implementation for easy transport integration with Netcode.

UNet is a deprecated solution that is no longer supported after Unity 2022.2. Unity Transport Package is the default transport for Netcode for GameObjects. We recommend transitioning to Unity Transport as soon as possible.
## Single player transport

### Community Transports or Writing Your Own
Netcode also provides a [single player transport](./singleplayer.md) that allows for easy switching between multiplayer and single player configurations.

## Community Transports or Writing Your Own

You can use any of the community contributed custom transport implementations or write your own.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,22 @@ You can define additional custom command-line arguments and retrieve them throug
## Example

The following code shows you an example of defining and then reading a custom command-line argument.
```
private const string k_OverrideArg = "-argName";

private bool ParseCommandLineOptions(out string command)
{
if (CommandLineOptions.Instance.GetArg(k_OverrideArg) is string argValue)
{
command = argValue;
return true;
}
command = default;
return false;
}
```

[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#DefineAndRead)]

Usage example:

```
if (ParseCommandLineOptions(out var command))
{
// Your logic here
}
```
[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#Usage)]

## Override connection data

If you want to ignore the connection port provided through command-line arguments, you can override it by using the optional `forceOverride` parameter in:
By default, the command line provided connection port and ip address take precedence over runtime configured values when using the [Unity transport](./advanced-topics/transports.md#unity-transport-package).

```
UnityTransport.SetConnectionData(string ip, ushort port, string listenAddress, bool forceOverride);
```
> [!NOTE]
> When the [Unity dedicated server package](https://docs.unity3d.com/Documentation/Manual/dedicated-server.html) is installed, Unity transport will use the port and ip address provided by the dedicated server package.

Setting `forceOverride` to `true` ensures that the values you pass to `SetConnectionData` override any values specified via command-line arguments.
If you want to ignore the connection port provided through command-line arguments, you can override it by setting the `forceOverrideCommandLineArgs` parameter of UnityTransport's [`SetConnectionData`](xref:Unity.Netcode.Transports.UTP.UnityTransport.SetConnectionData(System.Boolean,System.String,System.UInt16,System.String)). Setting `forceOverrideCommandLineArgs` to `true` ensures that the values you pass to `SetConnectionData` will override any values specified via command-line arguments.

## Additional resources

- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/6000.2/Documentation/Manual/CommandLineArguments.html)
- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html)
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,6 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly,
private const string k_RpcAttribute_Delivery = nameof(RpcAttribute.Delivery);
private const string k_RpcAttribute_InvokePermission = nameof(RpcAttribute.InvokePermission);

#pragma warning disable CS0618 // Type or member is obsolete
// Need to ignore the obsolete warning as the obsolete behaviour still needs to work
private const string k_ServerRpcAttribute_RequireOwnership = nameof(ServerRpcAttribute.RequireOwnership);
#pragma warning restore CS0618 // Type or member is obsolete

private const string k_RpcParams_Server = nameof(__RpcParams.Server);
private const string k_RpcParams_Client = nameof(__RpcParams.Client);
private const string k_RpcParams_Ext = nameof(__RpcParams.Ext);
Expand Down Expand Up @@ -1502,10 +1497,6 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass
{
switch (attrField.Name)
{
case k_ServerRpcAttribute_RequireOwnership:
var requireOwnership = attrField.Argument.Type == rpcHandler.Module.TypeSystem.Boolean && (bool)attrField.Argument.Value;
invokePermission = requireOwnership ? RpcInvokePermission.Owner : RpcInvokePermission.Everyone;
break;
case k_RpcAttribute_InvokePermission:
invokePermission = (RpcInvokePermission)attrField.Argument.Value;
break;
Expand Down Expand Up @@ -1692,28 +1683,6 @@ private CustomAttribute CheckAndGetRpcAttribute(MethodDefinition methodDefinitio
return null;
}

bool hasInvokePermission = false, hasRequireOwnership = false;

foreach (var argument in rpcAttribute.Fields)
{
switch (argument.Name)
{
case k_ServerRpcAttribute_RequireOwnership:
hasRequireOwnership = true;
break;
case k_RpcAttribute_InvokePermission:
hasInvokePermission = true;
break;
}
}

if (hasInvokePermission && hasRequireOwnership)
{
m_Diagnostics.AddError($"{methodDefinition.Name} cannot declare both RequireOwnership and InvokePermission!");
return null;
}


// Checks for IsSerializable are moved to later as the check is now done by dynamically seeing if any valid
// serializer OR extension method exists for it.
return rpcAttribute;
Expand Down Expand Up @@ -2180,7 +2149,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName;
var isClientRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ClientRpcAttribute_FullName;
var isGenericRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.RpcAttribute_FullName;
var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership`
var rpcDelivery = RpcDelivery.Reliable; // default value MUST be == `RpcAttribute.Delivery`
var defaultTarget = SendTo.Everyone;
var allowTargetOverride = false;
Expand All @@ -2196,9 +2164,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
case k_RpcAttribute_Delivery:
rpcDelivery = (RpcDelivery)attrField.Argument.Value;
break;
case k_ServerRpcAttribute_RequireOwnership:
requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
break;
case nameof(RpcAttribute.AllowTargetOverride):
allowTargetOverride = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
break;
Expand Down Expand Up @@ -2320,7 +2285,8 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
{
// ServerRpc

if (requireOwnership)
// Require ownership check.
// Only the owner of an object can send a ServerRPC
{
var roReturnInstr = processor.Create(OpCodes.Ret);
var roLastInstr = processor.Create(OpCodes.Nop);
Expand All @@ -2347,7 +2313,7 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
instructions.Add(processor.Create(OpCodes.Brfalse, logNextInstr));

// Debug.LogError(...);
instructions.Add(processor.Create(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!"));
instructions.Add(processor.Create(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc!"));
instructions.Add(processor.Create(OpCodes.Call, m_Debug_LogError_MethodRef));

instructions.Add(logNextInstr);
Expand Down Expand Up @@ -2963,16 +2929,6 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
var processor = rpcHandler.Body.GetILProcessor();

var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName;
var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership`
foreach (var attrField in rpcAttribute.Fields)
{
switch (attrField.Name)
{
case k_ServerRpcAttribute_RequireOwnership:
requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
break;
}
}

rpcHandler.Body.InitLocals = true;
// NetworkManager networkManager;
Expand All @@ -2999,7 +2955,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
processor.Append(lastInstr);
}

if (isServerRpc && requireOwnership)
if (isServerRpc)
{
var roReturnInstr = processor.Create(OpCodes.Ret);
var roLastInstr = processor.Create(OpCodes.Nop);
Expand Down Expand Up @@ -3028,7 +2984,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
processor.Emit(OpCodes.Brfalse, logNextInstr);

// Debug.LogError(...);
processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!");
processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc!");
processor.Emit(OpCodes.Call, m_Debug_LogError_MethodRef);

processor.Append(logNextInstr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)

switch (typeDefinition.Name)
{
case nameof(NetworkManager):
ProcessNetworkManager(typeDefinition, compiledAssembly.Defines);
break;
case nameof(NetworkBehaviour):
ProcessNetworkBehaviour(typeDefinition);
break;
Expand Down Expand Up @@ -90,46 +87,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
}

// TODO: Deprecate...
// This is changing accessibility for values that are no longer used, but since our validator runs
// after ILPP and sees those values as public, they cannot be removed until a major version change.
private void ProcessNetworkManager(TypeDefinition typeDefinition, string[] assemblyDefines)
{
foreach (var fieldDefinition in typeDefinition.Fields)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_func_table))
#pragma warning restore CS0618 // Type or member is obsolete
{
fieldDefinition.IsPublic = true;
}

#pragma warning disable CS0618 // Type or member is obsolete
if (fieldDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
#pragma warning restore CS0618 // Type or member is obsolete
{
fieldDefinition.IsPublic = true;
}

#pragma warning disable CS0618 // Type or member is obsolete
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_name_table))
#pragma warning restore CS0618 // Type or member is obsolete
{
fieldDefinition.IsPublic = true;
}
}

foreach (var nestedTypeDefinition in typeDefinition.NestedTypes)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (nestedTypeDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
#pragma warning restore CS0618 // Type or member is obsolete
{
nestedTypeDefinition.IsNestedPublic = true;
}
}
}

private void ProcessNetworkBehaviour(TypeDefinition typeDefinition)
{
foreach (var nestedType in typeDefinition.NestedTypes)
Expand Down
4 changes: 0 additions & 4 deletions com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ public override void OnInspectorGUI()
EditorGUILayout.Toggle(nameof(NetworkObject.IsOwner), m_NetworkObject.IsOwner);
EditorGUILayout.Toggle(nameof(NetworkObject.IsOwnedByServer), m_NetworkObject.IsOwnedByServer);
EditorGUILayout.Toggle(nameof(NetworkObject.IsPlayerObject), m_NetworkObject.IsPlayerObject);
#pragma warning disable CS0618 // Type or member is obsolete
// TODO-3.x: Update name in 3.x branch
EditorGUILayout.Toggle(nameof(NetworkObject.IsSceneObject), m_NetworkObject.InScenePlaced);
#pragma warning restore CS0618 // Type or member is obsolete
EditorGUILayout.Toggle(nameof(NetworkObject.DestroyWithScene), m_NetworkObject.DestroyWithScene);
EditorGUILayout.TextField(nameof(NetworkObject.NetworkManager), m_NetworkObject.NetworkManager == null ? "null" : m_NetworkObject.NetworkManager.gameObject.name);
GUI.enabled = guiEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ private float GetPrecision()
/// <remarks>
/// This is replaced by the <see cref="m_BufferQueue"/> of type <see cref="Queue{T}"/>.
/// </remarks>
[Obsolete("This list is no longer used and will be deprecated.", false)]
[Obsolete("This list is no longer used and will be deprecated.", true)]
protected internal readonly List<BufferedItem> m_Buffer = new List<BufferedItem>();

/// <summary>
/// ** Deprecating **
/// The starting value of type <see cref="T"/> to interpolate from.
/// </summary>
[Obsolete("This property will be deprecated.", false)]
[Obsolete("This property will be deprecated.", true)]
protected internal T m_InterpStartValue;

/// <summary>
/// ** Deprecating **
/// The current value of type <see cref="T"/>.
/// </summary>
[Obsolete("This property will be deprecated.", false)]
[Obsolete("This property will be deprecated.", true)]
protected internal T m_CurrentInterpValue;

/// <summary>
/// ** Deprecating **
/// The end (or target) value of type <see cref="T"/> to interpolate towards.
/// </summary>
[Obsolete("This property will be deprecated.", false)]
[Obsolete("This property will be deprecated.", true)]
protected internal T m_InterpEndValue;
#endregion

Expand Down Expand Up @@ -651,7 +651,7 @@ public T Update(float deltaTime, double renderTime, double serverTime)
/// <param name="deltaTime">time since call</param>
/// <param name="serverTime">current server time</param>
/// <returns>The newly interpolated value of type 'T'</returns>
[Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", false)]
[Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", true)]
public T Update(float deltaTime, NetworkTime serverTime)
{
return UpdateInternal(deltaTime, serverTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3861,17 +3861,6 @@ protected void Initialize()

#region PARENTING AND OWNERSHIP
/// <inheritdoc/>
public override void OnLostOwnership()
{
base.OnLostOwnership();
}

/// <inheritdoc/>
public override void OnGainedOwnership()
{
base.OnGainedOwnership();
}
/// <inheritdoc/>
protected override void OnOwnershipChanged(ulong previous, ulong current)
{
// If we were the previous owner or the newly assigned owner then reinitialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CommandLineOptions
/// <summary>
/// Command-line options singleton
/// </summary>
[Obsolete("Not used anymore replaced by TryGetArg")]
[Obsolete("Not used anymore replaced by TryGetArg", true)]
Comment thread
EmandM marked this conversation as resolved.
public static CommandLineOptions Instance
{
get
Expand All @@ -38,7 +38,7 @@ private set
/// </summary>
/// <param name="arg">The name of the argument</param>
/// <returns><see cref="string"/>Value of the command line argument passed in.</returns>
[Obsolete("Not used anymore replaced by TryGetArg")]
[Obsolete("Not used anymore replaced by TryGetArg", true)]
public string GetArg(string arg)
{
var argIndex = k_CommandLineArguments.IndexOf(arg);
Expand Down
Loading