diff --git a/CHANGELOG.md b/CHANGELOG.md index ab0fd6a..d53a191 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). +## [1.7.1] - 2023-11-15 + +### Added + +### Fixed + +- Fixed a bug where having a class with Rpcs that inherits from a class without Rpcs that inherits from NetworkVariable would cause a compile error. (#2751) +- Fixed issue where `NetworkBehaviour.Synchronize` was not truncating the write buffer if nothing was serialized during `NetworkBehaviour.OnSynchronize` causing an additional 6 bytes to be written per `NetworkBehaviour` component instance. (#2749) + +### Changed + ## [1.7.0] - 2023-10-11 ### Added diff --git a/Documentation~/index.md b/Documentation~/index.md index aad2141..31e766f 100644 --- a/Documentation~/index.md +++ b/Documentation~/index.md @@ -9,7 +9,7 @@ See guides below to install Unity Netcode for GameObjects, set up your project, - [Documentation](https://docs-multiplayer.unity3d.com/netcode/current/about) - [Installation](https://docs-multiplayer.unity3d.com/netcode/current/installation) - [First Steps](https://docs-multiplayer.unity3d.com/netcode/current/tutorials/get-started-ngo) -- [API Reference](https://docs-multiplayer.unity3d.com/netcode/current/api/introduction) +- [API Reference](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@1.6/api/index.html) # Technical details diff --git a/Editor/CodeGen/NetworkBehaviourILPP.cs b/Editor/CodeGen/NetworkBehaviourILPP.cs index c15ea8a..0f33294 100644 --- a/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -1237,8 +1237,10 @@ namespace Unity.Netcode.Editor.CodeGen } } - if (rpcHandlers.Count > 0) + //if (rpcHandlers.Count > 0) { + + // This always needs to generate even if it's empty. var initializeRpcsMethodDef = new MethodDefinition( k_NetworkBehaviour___initializeRpcs, MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig, diff --git a/Runtime/Core/NetworkBehaviour.cs b/Runtime/Core/NetworkBehaviour.cs index e0d0f21..7a5bd73 100644 --- a/Runtime/Core/NetworkBehaviour.cs +++ b/Runtime/Core/NetworkBehaviour.cs @@ -993,6 +993,8 @@ namespace Unity.Netcode if (finalPosition == positionBeforeSynchronize || threwException) { writer.Seek(positionBeforeWrite); + // Truncate back to the size before + writer.Truncate(); return false; } else diff --git a/Runtime/Core/NetworkManager.cs b/Runtime/Core/NetworkManager.cs index 4270331..78301e7 100644 --- a/Runtime/Core/NetworkManager.cs +++ b/Runtime/Core/NetworkManager.cs @@ -412,6 +412,19 @@ namespace Unity.Netcode internal NetworkConnectionManager ConnectionManager = new NetworkConnectionManager(); internal NetworkMessageManager MessageManager = null; + internal struct Override + { + 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 PortOverride; + #if UNITY_EDITOR internal static INetworkManagerHelper NetworkManagerHelper; @@ -658,6 +671,8 @@ namespace Unity.Netcode return; } + ParseCommandLineOptions(); + if (NetworkConfig.NetworkTransport == null) { if (NetworkLog.CurrentLogLevel <= LogLevel.Error) @@ -1100,5 +1115,39 @@ namespace Unity.Netcode Singleton = null; } } + + // 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(string arg, ref Override 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 + } } } diff --git a/Runtime/Transports/UNET/UNetTransport.cs b/Runtime/Transports/UNET/UNetTransport.cs index c03f415..474ce75 100644 --- a/Runtime/Transports/UNET/UNetTransport.cs +++ b/Runtime/Transports/UNET/UNetTransport.cs @@ -199,7 +199,7 @@ namespace Unity.Netcode.Transports.UNET public override bool StartClient() { m_ServerHostId = UnityEngine.Networking.NetworkTransport.AddHost(new HostTopology(GetConfig(), 1), 0, null); - m_ServerConnectionId = UnityEngine.Networking.NetworkTransport.Connect(m_ServerHostId, ConnectAddress, ConnectPort, 0, out byte error); + m_ServerConnectionId = UnityEngine.Networking.NetworkTransport.Connect(m_ServerHostId, ConnectAddress, GetConnectPort(), 0, out byte error); return (NetworkError)error == NetworkError.Ok; } @@ -207,7 +207,7 @@ namespace Unity.Netcode.Transports.UNET { var topology = new HostTopology(GetConfig(), MaxConnections); // Undocumented, but AddHost returns -1 in case of any type of failure. See UNET::NetLibraryManager::AddHost - return -1 != UnityEngine.Networking.NetworkTransport.AddHost(topology, ServerListenPort, null); + return -1 != UnityEngine.Networking.NetworkTransport.AddHost(topology, GetServerListenPort(), null); } public override void DisconnectRemoteClient(ulong clientId) @@ -281,6 +281,26 @@ namespace Unity.Netcode.Transports.UNET return connectionConfig; } + + private int GetConnectPort() + { + if (NetworkManager && NetworkManager.PortOverride.Overidden) + { + return NetworkManager.PortOverride.Value; + } + + return ConnectPort; + } + + private int GetServerListenPort() + { + if (NetworkManager && NetworkManager.PortOverride.Overidden) + { + return NetworkManager.PortOverride.Value; + } + + return ServerListenPort; + } } } #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/Runtime/Transports/UTP/UnityTransport.cs b/Runtime/Transports/UTP/UnityTransport.cs index 4576404..64e6033 100644 --- a/Runtime/Transports/UTP/UnityTransport.cs +++ b/Runtime/Transports/UTP/UnityTransport.cs @@ -402,6 +402,7 @@ namespace Unity.Netcode.Transports.UTP /// - packet jitter (variances in latency, see: https://en.wikipedia.org/wiki/Jitter) /// - packet drop rate (packet loss) /// + #if UTP_TRANSPORT_2_0_ABOVE [Obsolete("DebugSimulator is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)] #endif @@ -685,9 +686,11 @@ namespace Unity.Netcode.Transports.UTP /// Packet delay in milliseconds. /// Packet jitter in milliseconds. /// Packet drop percentage. + #if UTP_TRANSPORT_2_0_ABOVE [Obsolete("SetDebugSimulatorParameters is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)] #endif + public void SetDebugSimulatorParameters(int packetDelay, int packetJitter, int dropRate) { if (m_Driver.IsCreated) @@ -1209,6 +1212,11 @@ namespace Unity.Netcode.Transports.UTP NetworkManager = networkManager; + if (NetworkManager && NetworkManager.PortOverride.Overidden) + { + ConnectionData.Port = NetworkManager.PortOverride.Value; + } + m_RealTimeProvider = NetworkManager ? NetworkManager.RealTimeProvider : new RealTimeProvider(); m_NetworkSettings = new NetworkSettings(Allocator.Persistent); diff --git a/Runtime/com.unity.netcode.runtime.asmdef b/Runtime/com.unity.netcode.runtime.asmdef index beeb62a..3b673da 100644 --- a/Runtime/com.unity.netcode.runtime.asmdef +++ b/Runtime/com.unity.netcode.runtime.asmdef @@ -41,6 +41,11 @@ "name": "com.unity.transport", "expression": "2.1.0", "define": "UTP_TRANSPORT_2_1_ABOVE" + }, + { + "name": "Unity", + "expression": "2023", + "define": "UNITY_DEDICATED_SERVER_ARGUMENTS_PRESENT" } ] } diff --git a/Tests/Runtime/RpcTests.cs b/Tests/Runtime/RpcTests.cs index d676a14..16d206a 100644 --- a/Tests/Runtime/RpcTests.cs +++ b/Tests/Runtime/RpcTests.cs @@ -12,6 +12,20 @@ namespace Unity.Netcode.RuntimeTests { public class RpcTests : NetcodeIntegrationTest { + public class CompileTimeNoRpcsBaseClassTest : NetworkBehaviour + { + + } + + public class CompileTimeHasRpcsChildClassDerivedFromNoRpcsBaseClassTest : CompileTimeNoRpcsBaseClassTest + { + [ServerRpc] + public void SomeDummyServerRpc() + { + + } + } + public class GenericRpcTestNB : NetworkBehaviour where T : unmanaged { public event Action OnServer_Rpc; diff --git a/package.json b/package.json index 4db8def..904609d 100644 --- a/package.json +++ b/package.json @@ -2,23 +2,23 @@ "name": "com.unity.netcode.gameobjects", "displayName": "Netcode for GameObjects", "description": "Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.", - "version": "1.7.0", + "version": "1.7.1", "unity": "2020.3", "dependencies": { "com.unity.nuget.mono-cecil": "1.10.1", "com.unity.transport": "1.4.0" }, "_upm": { - "changelog": "### Added\n\n- exposed NetworkObject.GetNetworkBehaviourAtOrderIndex as a public API (#2724)\n- Added context menu tool that provides users with the ability to quickly update the GlobalObjectIdHash value for all in-scene placed prefab instances that were created prior to adding a NetworkObject component to it. (#2707)\n- Added methods NetworkManager.SetPeerMTU and NetworkManager.GetPeerMTU to be able to set MTU sizes per-peer (#2676)\n- Added `GenerateSerializationForGenericParameterAttribute`, which can be applied to user-created Network Variable types to ensure the codegen generates serialization for the generic types they wrap. (#2694)\n- Added `GenerateSerializationForTypeAttribute`, which can be applied to any class or method to ensure the codegen generates serialization for the specific provided type. (#2694)\n- Exposed `NetworkVariableSerialization.Read`, `NetworkVariableSerialization.Write`, `NetworkVariableSerialization.AreEqual`, and `NetworkVariableSerialization.Duplicate` to further support the creation of user-created network variables by allowing users to access the generated serialization methods and serialize generic types efficiently without boxing. (#2694)\n- Added `NetworkVariableBase.MarkNetworkBehaviourDirty` so that user-created network variable types can mark their containing `NetworkBehaviour` to be processed by the update loop. (#2694)\n\n### Fixed\n\n- Fixed issue where the server side `NetworkSceneManager` instance was not adding the currently active scene to its list of scenes loaded. (#2723)\n- Generic NetworkBehaviour types no longer result in compile errors or runtime errors (#2720)\n- Rpcs within Generic NetworkBehaviour types can now serialize parameters of the class's generic types (but may not have generic types of their own) (#2720)\n- Errors are no longer thrown when entering play mode with domain reload disabled (#2720)\n- NetworkSpawn is now correctly called each time when entering play mode with scene reload disabled (#2720)\n- NetworkVariables of non-integer types will no longer break the inspector (#2714)\n- NetworkVariables with NonSerializedAttribute will not appear in the inspector (#2714)\n- Fixed issue where `UnityTransport` would attempt to establish WebSocket connections even if using UDP/DTLS Relay allocations when the build target was WebGL. This only applied to working in the editor since UDP/DTLS can't work in the browser. (#2695)\n- Fixed issue where a `NetworkBehaviour` component's `OnNetworkDespawn` was not being invoked on the host-server side for an in-scene placed `NetworkObject` when a scene was unloaded (during a scene transition) and the `NetworkBehaviour` component was positioned/ordered before the `NetworkObject` component. (#2685)\n- Fixed issue where `SpawnWithObservers` was not being honored when `NetworkConfig.EnableSceneManagement` was disabled. (#2682)\n- Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674)\n- Fixed \"writing past the end of the buffer\" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. (#2670)\n- Fixed issue where generation of the `DefaultNetworkPrefabs` asset was not enabled by default. (#2662)\n- Fixed issue where the `GlobalObjectIdHash` value could be updated but the asset not marked as dirty. (#2662)\n- Fixed issue where the `GlobalObjectIdHash` value of a (network) prefab asset could be assigned an incorrect value when editing the prefab in a temporary scene. (#2662)\n- Fixed issue where the `GlobalObjectIdHash` value generated after creating a (network) prefab from an object constructed within the scene would not be the correct final value in a stand alone build. (#2662)\n\n### Changed\n\n- Updated dependency on `com.unity.transport` to version 1.4.0. (#2716)" + "changelog": "### Added\n\n### Fixed\n\n- Fixed a bug where having a class with Rpcs that inherits from a class without Rpcs that inherits from NetworkVariable would cause a compile error. (#2751)\n- Fixed issue where `NetworkBehaviour.Synchronize` was not truncating the write buffer if nothing was serialized during `NetworkBehaviour.OnSynchronize` causing an additional 6 bytes to be written per `NetworkBehaviour` component instance. (#2749)\n\n### Changed" }, "upmCi": { - "footprint": "87fd22da62ed4e055a6eead5cea85b4b449eded0" + "footprint": "0aa1a9720f4e4850c481cc1bb159b646494808e1" }, "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@1.7/manual/index.html", "repository": { "url": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git", "type": "git", - "revision": "f4004c72eb46bf2aac62bc71b599017bd0570fdb" + "revision": "5df824c7588b43c29238a927d14642d5f94129ff" }, "samples": [ {