Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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
  • Loading branch information
Unity Technologies committed Nov 15, 2023
1 parent ffef45b commit 514166e
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 8 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Documentation~/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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[email protected]/api/index.html)

# Technical details

Expand Down
4 changes: 3 additions & 1 deletion Editor/CodeGen/NetworkBehaviourILPP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,10 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass
}
}

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,
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Core/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,8 @@ internal bool Synchronize<T>(ref BufferSerializer<T> serializer, ulong targetCli
if (finalPosition == positionBeforeSynchronize || threwException)
{
writer.Seek(positionBeforeWrite);
// Truncate back to the size before
writer.Truncate();
return false;
}
else
Expand Down
49 changes: 49 additions & 0 deletions Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,19 @@ 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;

#if UNITY_EDITOR
internal static INetworkManagerHelper NetworkManagerHelper;

Expand Down Expand Up @@ -658,6 +671,8 @@ internal void Initialize(bool server)
return;
}

ParseCommandLineOptions();

if (NetworkConfig.NetworkTransport == null)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
Expand Down Expand Up @@ -1100,5 +1115,39 @@ private void OnDestroy()
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<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
}
}
}
24 changes: 22 additions & 2 deletions Runtime/Transports/UNET/UNetTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ public override NetworkEvent PollEvent(out ulong clientId, out ArraySegment<byte
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;
}

public override bool StartServer()
{
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)
Expand Down Expand Up @@ -281,6 +281,26 @@ private ConnectionConfig GetConfig()

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
Expand Down
8 changes: 8 additions & 0 deletions Runtime/Transports/UTP/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public struct SimulatorParameters
/// - packet jitter (variances in latency, see: https://en.wikipedia.org/wiki/Jitter)
/// - packet drop rate (packet loss)
/// </summary>

#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
Expand Down Expand Up @@ -685,9 +686,11 @@ public void SetConnectionData(NetworkEndpoint endPoint, NetworkEndpoint listenEn
/// <param name="packetDelay">Packet delay in milliseconds.</param>
/// <param name="packetJitter">Packet jitter in milliseconds.</param>
/// <param name="dropRate">Packet drop percentage.</param>

#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)
Expand Down Expand Up @@ -1209,6 +1212,11 @@ public override void Initialize(NetworkManager networkManager = null)

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);
Expand Down
5 changes: 5 additions & 0 deletions Runtime/com.unity.netcode.runtime.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
14 changes: 14 additions & 0 deletions Tests/Runtime/RpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : NetworkBehaviour where T : unmanaged
{
public event Action<T, ServerRpcParams> OnServer_Rpc;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>.Read`, `NetworkVariableSerialization<T>.Write`, `NetworkVariableSerialization<T>.AreEqual`, and `NetworkVariableSerialization<T>.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/[email protected]/manual/index.html",
"repository": {
"url": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git",
"type": "git",
"revision": "f4004c72eb46bf2aac62bc71b599017bd0570fdb"
"revision": "5df824c7588b43c29238a927d14642d5f94129ff"
},
"samples": [
{
Expand Down

0 comments on commit 514166e

Please sign in to comment.