Skip to content

Commit 7b97b5b

Browse files
chore: Swap Obsolete tags from warning to error (#4149)
* Made more obsolete apis throw errors * updated more APIs * Delete obsolete code * Move outdated docs code to docs tests and update some docs * Add errors to missed obsolete tags * typo fix * removed old API * Add missed removals * RequireOwnership defaulted to true. Keep the IL2CPP code that does the ownership checks on a ServerRPC --------- Co-authored-by: Emma <emma.mcmillan@unity3d.com>
1 parent dd472a6 commit 7b97b5b

24 files changed

Lines changed: 104 additions & 232 deletions

File tree

Examples/OverridingScenesAndPrefabs/Assets/Scripts/NetworkManagerBootstrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ private void StartDedicatedServer()
499499
// Set the application frame rate to like 30 to reduce frame processing overhead
500500
Application.targetFrameRate = 30;
501501

502-
Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}");
502+
Debug.Log($"[Pre-Init] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}");
503503
Debug.Log($"[Pre-Init] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}");
504504
// Setup your IP and port sepcific to your DGS
505505
//unityTransport.SetConnectionData(ListenAddress, ListenPort, ListenAddress);
@@ -527,7 +527,7 @@ private void StartDedicatedServer()
527527
private void ServerStarted()
528528
{
529529
Debug.Log("Dedicated Server Started!");
530-
Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.ServerEndPoint}");
530+
Debug.Log($"[Started] Server Address Endpoint: {m_UnityTransport.ConnectionData.Address}:{m_UnityTransport.ConnectionData.Port}");
531531
Debug.Log($"[Started] Server Listen Endpoint: {m_UnityTransport.ConnectionData.ListenEndPoint}");
532532
Debug.Log("===============================================================");
533533
Debug.Log("[X] Exits session (Shutdown) | [ESC] Exits application instance");

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
2020

2121
### Deprecated
2222

23+
- Several APIs that were already marked `[Obsolete]` with a warning now raise a compile error instead (they are not removed yet).
24+
2325
### Removed
2426

2527
### Fixed

com.unity.netcode.gameobjects/Documentation~/advanced-topics/transports.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Transports
22

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

55
## So what is a transport layer?
66

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

1919
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).
2020

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

23-
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.
23+
## Single player transport
2424

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

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

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,22 @@ You can define additional custom command-line arguments and retrieve them throug
2323
## Example
2424

2525
The following code shows you an example of defining and then reading a custom command-line argument.
26-
```
27-
private const string k_OverrideArg = "-argName";
28-
29-
private bool ParseCommandLineOptions(out string command)
30-
{
31-
if (CommandLineOptions.Instance.GetArg(k_OverrideArg) is string argValue)
32-
{
33-
command = argValue;
34-
return true;
35-
}
36-
command = default;
37-
return false;
38-
}
39-
```
26+
27+
[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#DefineAndRead)]
4028

4129
Usage example:
4230

43-
```
44-
if (ParseCommandLineOptions(out var command))
45-
{
46-
// Your logic here
47-
}
48-
```
31+
[!code-cs[](../Tests/Runtime/DocumentationCodeSamples/Configuration/CommandLineOptionsDocsTests.cs#Usage)]
4932

5033
## Override connection data
5134

52-
If you want to ignore the connection port provided through command-line arguments, you can override it by using the optional `forceOverride` parameter in:
35+
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).
5336

54-
```
55-
UnityTransport.SetConnectionData(string ip, ushort port, string listenAddress, bool forceOverride);
56-
```
37+
> [!NOTE]
38+
> 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.
5739
58-
Setting `forceOverride` to `true` ensures that the values you pass to `SetConnectionData` override any values specified via command-line arguments.
40+
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.
5941

6042
## Additional resources
6143

62-
- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/6000.2/Documentation/Manual/CommandLineArguments.html)
44+
- [Command-line arguments in the Unity Manual](https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html)

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,6 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly,
617617
private const string k_RpcAttribute_Delivery = nameof(RpcAttribute.Delivery);
618618
private const string k_RpcAttribute_InvokePermission = nameof(RpcAttribute.InvokePermission);
619619

620-
#pragma warning disable CS0618 // Type or member is obsolete
621-
// Need to ignore the obsolete warning as the obsolete behaviour still needs to work
622-
private const string k_ServerRpcAttribute_RequireOwnership = nameof(ServerRpcAttribute.RequireOwnership);
623-
#pragma warning restore CS0618 // Type or member is obsolete
624-
625620
private const string k_RpcParams_Server = nameof(__RpcParams.Server);
626621
private const string k_RpcParams_Client = nameof(__RpcParams.Client);
627622
private const string k_RpcParams_Ext = nameof(__RpcParams.Ext);
@@ -1502,10 +1497,6 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass
15021497
{
15031498
switch (attrField.Name)
15041499
{
1505-
case k_ServerRpcAttribute_RequireOwnership:
1506-
var requireOwnership = attrField.Argument.Type == rpcHandler.Module.TypeSystem.Boolean && (bool)attrField.Argument.Value;
1507-
invokePermission = requireOwnership ? RpcInvokePermission.Owner : RpcInvokePermission.Everyone;
1508-
break;
15091500
case k_RpcAttribute_InvokePermission:
15101501
invokePermission = (RpcInvokePermission)attrField.Argument.Value;
15111502
break;
@@ -1692,28 +1683,6 @@ private CustomAttribute CheckAndGetRpcAttribute(MethodDefinition methodDefinitio
16921683
return null;
16931684
}
16941685

1695-
bool hasInvokePermission = false, hasRequireOwnership = false;
1696-
1697-
foreach (var argument in rpcAttribute.Fields)
1698-
{
1699-
switch (argument.Name)
1700-
{
1701-
case k_ServerRpcAttribute_RequireOwnership:
1702-
hasRequireOwnership = true;
1703-
break;
1704-
case k_RpcAttribute_InvokePermission:
1705-
hasInvokePermission = true;
1706-
break;
1707-
}
1708-
}
1709-
1710-
if (hasInvokePermission && hasRequireOwnership)
1711-
{
1712-
m_Diagnostics.AddError($"{methodDefinition.Name} cannot declare both RequireOwnership and InvokePermission!");
1713-
return null;
1714-
}
1715-
1716-
17171686
// Checks for IsSerializable are moved to later as the check is now done by dynamically seeing if any valid
17181687
// serializer OR extension method exists for it.
17191688
return rpcAttribute;
@@ -2180,7 +2149,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
21802149
var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName;
21812150
var isClientRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ClientRpcAttribute_FullName;
21822151
var isGenericRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.RpcAttribute_FullName;
2183-
var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership`
21842152
var rpcDelivery = RpcDelivery.Reliable; // default value MUST be == `RpcAttribute.Delivery`
21852153
var defaultTarget = SendTo.Everyone;
21862154
var allowTargetOverride = false;
@@ -2196,9 +2164,6 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
21962164
case k_RpcAttribute_Delivery:
21972165
rpcDelivery = (RpcDelivery)attrField.Argument.Value;
21982166
break;
2199-
case k_ServerRpcAttribute_RequireOwnership:
2200-
requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
2201-
break;
22022167
case nameof(RpcAttribute.AllowTargetOverride):
22032168
allowTargetOverride = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
22042169
break;
@@ -2320,7 +2285,8 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
23202285
{
23212286
// ServerRpc
23222287

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

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

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

29652931
var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName;
2966-
var requireOwnership = true; // default value MUST be == `ServerRpcAttribute.RequireOwnership`
2967-
foreach (var attrField in rpcAttribute.Fields)
2968-
{
2969-
switch (attrField.Name)
2970-
{
2971-
case k_ServerRpcAttribute_RequireOwnership:
2972-
requireOwnership = attrField.Argument.Type == typeSystem.Boolean && (bool)attrField.Argument.Value;
2973-
break;
2974-
}
2975-
}
29762932

29772933
rpcHandler.Body.InitLocals = true;
29782934
// NetworkManager networkManager;
@@ -2999,7 +2955,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
29992955
processor.Append(lastInstr);
30002956
}
30012957

3002-
if (isServerRpc && requireOwnership)
2958+
if (isServerRpc)
30032959
{
30042960
var roReturnInstr = processor.Create(OpCodes.Ret);
30052961
var roLastInstr = processor.Create(OpCodes.Nop);
@@ -3028,7 +2984,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
30282984
processor.Emit(OpCodes.Brfalse, logNextInstr);
30292985

30302986
// Debug.LogError(...);
3031-
processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!");
2987+
processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc!");
30322988
processor.Emit(OpCodes.Call, m_Debug_LogError_MethodRef);
30332989

30342990
processor.Append(logNextInstr);

com.unity.netcode.gameobjects/Editor/CodeGen/RuntimeAccessModifiersILPP.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
4747

4848
switch (typeDefinition.Name)
4949
{
50-
case nameof(NetworkManager):
51-
ProcessNetworkManager(typeDefinition, compiledAssembly.Defines);
52-
break;
5350
case nameof(NetworkBehaviour):
5451
ProcessNetworkBehaviour(typeDefinition);
5552
break;
@@ -90,46 +87,6 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
9087
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
9188
}
9289

93-
// TODO: Deprecate...
94-
// This is changing accessibility for values that are no longer used, but since our validator runs
95-
// after ILPP and sees those values as public, they cannot be removed until a major version change.
96-
private void ProcessNetworkManager(TypeDefinition typeDefinition, string[] assemblyDefines)
97-
{
98-
foreach (var fieldDefinition in typeDefinition.Fields)
99-
{
100-
#pragma warning disable CS0618 // Type or member is obsolete
101-
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_func_table))
102-
#pragma warning restore CS0618 // Type or member is obsolete
103-
{
104-
fieldDefinition.IsPublic = true;
105-
}
106-
107-
#pragma warning disable CS0618 // Type or member is obsolete
108-
if (fieldDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
109-
#pragma warning restore CS0618 // Type or member is obsolete
110-
{
111-
fieldDefinition.IsPublic = true;
112-
}
113-
114-
#pragma warning disable CS0618 // Type or member is obsolete
115-
if (fieldDefinition.Name == nameof(NetworkManager.__rpc_name_table))
116-
#pragma warning restore CS0618 // Type or member is obsolete
117-
{
118-
fieldDefinition.IsPublic = true;
119-
}
120-
}
121-
122-
foreach (var nestedTypeDefinition in typeDefinition.NestedTypes)
123-
{
124-
#pragma warning disable CS0618 // Type or member is obsolete
125-
if (nestedTypeDefinition.Name == nameof(NetworkManager.RpcReceiveHandler))
126-
#pragma warning restore CS0618 // Type or member is obsolete
127-
{
128-
nestedTypeDefinition.IsNestedPublic = true;
129-
}
130-
}
131-
}
132-
13390
private void ProcessNetworkBehaviour(TypeDefinition typeDefinition)
13491
{
13592
foreach (var nestedType in typeDefinition.NestedTypes)

com.unity.netcode.gameobjects/Editor/NetworkObjectEditor.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ public override void OnInspectorGUI()
101101
EditorGUILayout.Toggle(nameof(NetworkObject.IsOwner), m_NetworkObject.IsOwner);
102102
EditorGUILayout.Toggle(nameof(NetworkObject.IsOwnedByServer), m_NetworkObject.IsOwnedByServer);
103103
EditorGUILayout.Toggle(nameof(NetworkObject.IsPlayerObject), m_NetworkObject.IsPlayerObject);
104-
#pragma warning disable CS0618 // Type or member is obsolete
105-
// TODO-3.x: Update name in 3.x branch
106-
EditorGUILayout.Toggle(nameof(NetworkObject.IsSceneObject), m_NetworkObject.InScenePlaced);
107-
#pragma warning restore CS0618 // Type or member is obsolete
108104
EditorGUILayout.Toggle(nameof(NetworkObject.DestroyWithScene), m_NetworkObject.DestroyWithScene);
109105
EditorGUILayout.TextField(nameof(NetworkObject.NetworkManager), m_NetworkObject.NetworkManager == null ? "null" : m_NetworkObject.NetworkManager.gameObject.name);
110106
GUI.enabled = guiEnabled;

com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ private float GetPrecision()
5959
/// <remarks>
6060
/// This is replaced by the <see cref="m_BufferQueue"/> of type <see cref="Queue{T}"/>.
6161
/// </remarks>
62-
[Obsolete("This list is no longer used and will be deprecated.", false)]
62+
[Obsolete("This list is no longer used and will be deprecated.", true)]
6363
protected internal readonly List<BufferedItem> m_Buffer = new List<BufferedItem>();
6464

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

7272
/// <summary>
7373
/// ** Deprecating **
7474
/// The current value of type <see cref="T"/>.
7575
/// </summary>
76-
[Obsolete("This property will be deprecated.", false)]
76+
[Obsolete("This property will be deprecated.", true)]
7777
protected internal T m_CurrentInterpValue;
7878

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

@@ -651,7 +651,7 @@ public T Update(float deltaTime, double renderTime, double serverTime)
651651
/// <param name="deltaTime">time since call</param>
652652
/// <param name="serverTime">current server time</param>
653653
/// <returns>The newly interpolated value of type 'T'</returns>
654-
[Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", false)]
654+
[Obsolete("This method is being deprecated due to it being only used for internal testing purposes.", true)]
655655
public T Update(float deltaTime, NetworkTime serverTime)
656656
{
657657
return UpdateInternal(deltaTime, serverTime);

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,17 +3861,6 @@ protected void Initialize()
38613861

38623862
#region PARENTING AND OWNERSHIP
38633863
/// <inheritdoc/>
3864-
public override void OnLostOwnership()
3865-
{
3866-
base.OnLostOwnership();
3867-
}
3868-
3869-
/// <inheritdoc/>
3870-
public override void OnGainedOwnership()
3871-
{
3872-
base.OnGainedOwnership();
3873-
}
3874-
/// <inheritdoc/>
38753864
protected override void OnOwnershipChanged(ulong previous, ulong current)
38763865
{
38773866
// If we were the previous owner or the newly assigned owner then reinitialize

com.unity.netcode.gameobjects/Runtime/Configuration/CommandLineOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CommandLineOptions
1212
/// <summary>
1313
/// Command-line options singleton
1414
/// </summary>
15-
[Obsolete("Not used anymore replaced by TryGetArg")]
15+
[Obsolete("Not used anymore replaced by TryGetArg", true)]
1616
public static CommandLineOptions Instance
1717
{
1818
get
@@ -38,7 +38,7 @@ private set
3838
/// </summary>
3939
/// <param name="arg">The name of the argument</param>
4040
/// <returns><see cref="string"/>Value of the command line argument passed in.</returns>
41-
[Obsolete("Not used anymore replaced by TryGetArg")]
41+
[Obsolete("Not used anymore replaced by TryGetArg", true)]
4242
public string GetArg(string arg)
4343
{
4444
var argIndex = k_CommandLineArguments.IndexOf(arg);

0 commit comments

Comments
 (0)