diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs index a72c9482e8..69e5de3ee0 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs @@ -285,7 +285,11 @@ private void DisplayNetworkManagerProperties() } } var networkPrefabs = m_NetworkManager.NetworkConfig.MigrateOldNetworkPrefabsToNetworkPrefabsList(); +#if UNITY_6000_2_OR_NEWER + string path = Path.Combine(directory, $"NetworkPrefabs-{m_NetworkManager.GetEntityId()}.asset"); +#else string path = Path.Combine(directory, $"NetworkPrefabs-{m_NetworkManager.GetInstanceID()}.asset"); +#endif Debug.Log("Saving migrated Network Prefabs List to " + path); AssetDatabase.CreateAsset(networkPrefabs, path); EditorUtility.SetDirty(m_NetworkManager); @@ -390,7 +394,8 @@ public override void OnInspectorGUI() #if !MULTIPLAYER_TOOLS DrawInstallMultiplayerToolsTip(); #endif - void SetExpanded(bool expanded) { networkManager.NetworkManagerExpanded = expanded; }; + void SetExpanded(bool expanded) { networkManager.NetworkManagerExpanded = expanded; } + ; DrawFoldOutGroup(networkManager.GetType(), DisplayNetworkManagerProperties, networkManager.NetworkManagerExpanded, SetExpanded); DisplayCallToActionButtons(); base.OnInspectorGUI(); diff --git a/com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs b/com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs index d5dff7e069..1421372839 100644 --- a/com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs @@ -125,7 +125,11 @@ public void RegisterHandler(IContactEventHandler contactEventHandler, bool regis { return; } +#if UNITY_6000_2_OR_NEWER + var instanceId = rigidbody.GetEntityId(); +#else var instanceId = rigidbody.GetInstanceID(); +#endif if (register) { if (!m_RigidbodyMapping.ContainsKey(instanceId)) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index e3cd4b0dd5..74d1a412f0 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -2217,6 +2217,7 @@ public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true) // DANGO-TODO: Do we want to worry about ownership permissions here? // It wouldn't make sense to not allow parenting, but keeping this note here as a reminder. var isAuthority = HasAuthority || (AllowOwnerToParent && IsOwner); + Debug.Log($"something is broken! isAuthority={isAuthority} | HasAuthority={HasAuthority} | (AllowOwnerToParent && IsOwner)={(AllowOwnerToParent && IsOwner)}"); // If we don't have authority and we are not shutting down, then don't allow any parenting. // If we are shutting down and don't have authority then allow it. @@ -2376,47 +2377,29 @@ private void OnTransformParentChanged() m_CachedWorldPositionStays = true; } - // If we are connected to a CMB service or we are running a mock CMB service then send to the "server" identifier - if (distributedAuthority || (!distributedAuthority && AllowOwnerToParent && IsOwner && !NetworkManager.IsServer)) + // If we're not the server, we should tell the server about this parent change + if (!NetworkManager.IsServer) { - if (!NetworkManager.DAHost) + // Don't send a message in DA mode if we're the only observers of this object (we're the only authority). + if (distributedAuthority && Observers.Count <= 1) { - NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType.DefaultDelivery, 0); return; } - else - { - foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds) - { - if (clientId == NetworkManager.ServerClientId) - { - continue; - } - NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType.DefaultDelivery, clientId); - } - } + + NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType.DefaultDelivery, NetworkManager.ServerClientId); + return; } - else + + // Otherwise we are a Server (client-server or DAHost). Send to all observers + foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds) { - // Otherwise we are running in client-server =or= this has to be a DAHost instance. - // Send to all connected clients. - unsafe + if (clientId == NetworkManager.ServerClientId) { - var maxCount = NetworkManager.ConnectedClientsIds.Count; - ulong* clientIds = stackalloc ulong[maxCount]; - int idx = 0; - foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds) - { - if (clientId == NetworkManager.ServerClientId) - { - continue; - } - if (Observers.Contains(clientId)) - { - clientIds[idx++] = clientId; - } - } - NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType.DefaultDelivery, clientIds, idx); + continue; + } + if (Observers.Contains(clientId)) + { + NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType.DefaultDelivery, clientId); } } } diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs index a0ccfc6ed3..5b71fcadbe 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs @@ -428,8 +428,11 @@ private void InitDriver() out m_UnreliableFragmentedPipeline, out m_UnreliableSequencedFragmentedPipeline, out m_ReliableSequencedPipeline); - +#if UNITY_6000_2_OR_NEWER + TransportInitialized?.Invoke(GetEntityId(), m_Driver); +#else TransportInitialized?.Invoke(GetInstanceID(), m_Driver); +#endif } private void DisposeInternals() @@ -446,7 +449,11 @@ private void DisposeInternals() m_SendQueue.Clear(); +#if UNITY_6000_2_OR_NEWER + TransportDisposed?.Invoke(GetEntityId()); +#else TransportDisposed?.Invoke(GetInstanceID()); +#endif } /// @@ -496,14 +503,11 @@ public NetworkSettings GetDefaultNetworkSettings() // Latency, jitter and packet loss will be set by the network simulator in the tools // package. We just need to initialize the settings since otherwise these features will // not be enabled at all in the driver. - settings.WithSimulatorStageParameters( - // Assuming a maximum average latency of 50 ms, and that we're somehow able to flush - // an entire reliable window every tick, then at 60 ticks per second we need to be - // able to store 60 * 0.05 * 64 = 192 packets per connection in the simulator - // pipeline stage. Double that since we handle both directions and round it up, and - // that's how we get 400 here. - maxPacketCount: 400, - randomSeed: DebugSimulatorRandomSeed ?? (uint)System.Diagnostics.Stopwatch.GetTimestamp()); + // Assuming a maximum average latency of 50 ms, and that we're somehow able to flush an entire reliable window every tick, + // then at 60 ticks per second we need to be able to store 60 * 0.05 * 64 = 192 packets per connection in the simulator + // pipeline stage. Double that since we handle both directions and round it up, and + // that's how we get 400 here. + settings.WithSimulatorStageParameters(maxPacketCount: 400, randomSeed: DebugSimulatorRandomSeed ?? (uint)System.Diagnostics.Stopwatch.GetTimestamp()); settings.WithNetworkSimulatorParameters(); #endif @@ -1100,15 +1104,18 @@ private void ExtractNetworkMetrics() { if (m_NetworkManager.IsServer) { - for (int i=0; i(); var nonAuthorityEulerRotation = nonAuthorityInstance.GetSpaceRelativeRotation().eulerAngles; @@ -173,7 +178,7 @@ public IEnumerator OrderOfOperations() var parent1 = m_AuthorityParentInstances[0]; var parent2 = m_AuthorityParentInstances[1]; - ConfigureSequencesTest1(parent1); + ConfigureSequencesTest1_ClientServerOnly(parent1); yield return RunTestSequences(); ConfigureSequencesTest2(parent1); @@ -288,12 +293,19 @@ private IEnumerator __RunTestSequences(bool spawnWithObservers = true, bool spaw #region Test Sequence Configurations /// + /// Client server only - under da mode only the authority can parent /// Test-1: /// Authority-> Spawn, change ownership, (wait), parent /// - private void ConfigureSequencesTest1(NetworkObject parent) + private void ConfigureSequencesTest1_ClientServerOnly(NetworkObject parent) { - SpawnSequenceController.CurrentTest = "Test1"; + SpawnSequenceController.CurrentTest = "Test1 (Client-Server Only)"; + if (m_AuthorityNetworkManager.DistributedAuthorityMode) + { + SpawnSequenceController.ClientServerOnly = true; + return; + } + var changeOwnershipSequence = new ChangeOwnershipSequence() { Stage = SpawnSequence.SpawnStage.AfterSpawn, @@ -305,6 +317,7 @@ private void ConfigureSequencesTest1(NetworkObject parent) TimeDelayInMS = 200, Stage = SpawnSequence.SpawnStage.AfterSpawn, TargetParent = parent, + InvokeOnlyOnClientId = GetAuthorityNetworkManager().LocalClientId, }; SpawnSequenceController.AddAction(changeOwnershipSequence); @@ -855,6 +868,10 @@ protected override bool OnShouldInvoke(SpawnStage stage) protected override void OnAction() { m_NetworkObject.ChangeOwnership(TargetOwnerClientId); + if (TargetOwnerClientId != m_NetworkObject.OwnerClientId) + { + Debug.LogError($"[{m_NetworkObject.name}] Failed to change ownership!"); + } base.OnAction(); } } @@ -866,7 +883,20 @@ internal class ParentSequence : SpawnSequence protected override bool OnShouldInvoke(SpawnStage stage) { - return base.OnShouldInvoke(stage) && (m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent)); + // Don't invoke if the base says no + if (!base.OnShouldInvoke(stage)) + { + return false; + } + + // If sequence is configured to specifically invoke on this client + if (InvokeOnlyOnClientId.HasValue && m_NetworkObject.NetworkManager.LocalClientId == InvokeOnlyOnClientId.Value) + { + return true; + } + + // Otherwise we should invoke if we have the authority to invoke + return m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent); } protected override void OnAction() diff --git a/testproject/Packages/manifest.json b/testproject/Packages/manifest.json index 1895c93dcc..8817bf5eaf 100644 --- a/testproject/Packages/manifest.json +++ b/testproject/Packages/manifest.json @@ -1,19 +1,20 @@ { "disableProjectUpdate": false, "dependencies": { - "com.unity.addressables": "2.2.2", - "com.unity.ai.navigation": "2.0.5", - "com.unity.collab-proxy": "2.6.0", - "com.unity.ide.rider": "3.0.31", - "com.unity.ide.visualstudio": "2.0.22", - "com.unity.mathematics": "1.3.2", + "com.unity.addressables": "2.7.4", + "com.unity.ai.navigation": "2.0.9", + "com.unity.collab-proxy": "2.9.3", + "com.unity.ide.rider": "3.0.38", + "com.unity.ide.visualstudio": "2.0.25", + "com.unity.mathematics": "1.3.3", + "com.unity.multiplayer.tools": "2.2.6", "com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects", "com.unity.package-validation-suite": "0.49.0-preview", - "com.unity.services.authentication": "3.4.0", - "com.unity.services.core": "1.14.0", - "com.unity.test-framework": "1.4.6", - "com.unity.test-framework.performance": "3.0.3", - "com.unity.timeline": "1.8.7", + "com.unity.services.authentication": "3.5.2", + "com.unity.services.multiplayer": "1.1.8", + "com.unity.test-framework": "1.6.0", + "com.unity.test-framework.performance": "3.1.0", + "com.unity.timeline": "1.8.9", "com.unity.ugui": "2.0.0", "com.unity.modules.accessibility": "1.0.0", "com.unity.modules.ai": "1.0.0", diff --git a/testproject/Packages/packages-lock.json b/testproject/Packages/packages-lock.json index dd5f6204a3..c87b451b63 100644 --- a/testproject/Packages/packages-lock.json +++ b/testproject/Packages/packages-lock.json @@ -1,22 +1,23 @@ { "dependencies": { "com.unity.addressables": { - "version": "2.2.2", + "version": "2.7.4", "depth": 0, "source": "registry", "dependencies": { "com.unity.profiling.core": "1.0.2", + "com.unity.test-framework": "1.4.5", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.imageconversion": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.scriptablebuildpipeline": "2.1.4", + "com.unity.scriptablebuildpipeline": "2.4.3", "com.unity.modules.unitywebrequestassetbundle": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.ai.navigation": { - "version": "2.0.5", + "version": "2.0.9", "depth": 0, "source": "registry", "dependencies": { @@ -25,8 +26,8 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.8.19", - "depth": 2, + "version": "1.8.24", + "depth": 1, "source": "registry", "dependencies": { "com.unity.mathematics": "1.2.1", @@ -35,20 +36,21 @@ "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "2.6.0", + "version": "2.9.3", "depth": 0, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.collections": { - "version": "2.5.1", - "depth": 2, + "version": "2.5.7", + "depth": 1, "source": "registry", "dependencies": { - "com.unity.burst": "1.8.17", - "com.unity.test-framework": "1.4.5", - "com.unity.nuget.mono-cecil": "1.11.4", + "com.unity.burst": "1.8.19", + "com.unity.mathematics": "1.3.2", + "com.unity.test-framework": "1.4.6", + "com.unity.nuget.mono-cecil": "1.11.5", "com.unity.test-framework.performance": "3.0.3" }, "url": "https://packages.unity.com" @@ -56,12 +58,11 @@ "com.unity.ext.nunit": { "version": "2.0.5", "depth": 1, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" + "source": "builtin", + "dependencies": {} }, "com.unity.ide.rider": { - "version": "3.0.31", + "version": "3.0.38", "depth": 0, "source": "registry", "dependencies": { @@ -70,21 +71,36 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.22", + "version": "2.0.25", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.9" + "com.unity.test-framework": "1.1.31" }, "url": "https://packages.unity.com" }, "com.unity.mathematics": { - "version": "1.3.2", + "version": "1.3.3", "depth": 0, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.multiplayer.tools": { + "version": "2.2.6", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.burst": "1.8.18", + "com.unity.collections": "2.5.1", + "com.unity.mathematics": "1.3.2", + "com.unity.profiling.core": "1.0.2", + "com.unity.nuget.mono-cecil": "1.11.4", + "com.unity.modules.uielements": "1.0.0", + "com.unity.nuget.newtonsoft-json": "3.2.1" + }, + "url": "https://packages.unity.com" + }, "com.unity.netcode.gameobjects": { "version": "file:../../com.unity.netcode.gameobjects", "depth": 0, @@ -95,7 +111,7 @@ } }, "com.unity.nuget.mono-cecil": { - "version": "1.11.4", + "version": "1.11.5", "depth": 1, "source": "registry", "dependencies": {}, @@ -125,27 +141,30 @@ "url": "https://packages.unity.com" }, "com.unity.scriptablebuildpipeline": { - "version": "2.1.4", + "version": "2.4.3", "depth": 1, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.unity.test-framework": "1.4.5", + "com.unity.modules.assetbundle": "1.0.0" + }, "url": "https://packages.unity.com" }, "com.unity.services.authentication": { - "version": "3.4.0", + "version": "3.5.2", "depth": 0, "source": "registry", "dependencies": { "com.unity.ugui": "1.0.0", - "com.unity.services.core": "1.14.0", + "com.unity.services.core": "1.15.1", "com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.modules.unitywebrequest": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.services.core": { - "version": "1.14.0", - "depth": 0, + "version": "1.15.1", + "depth": 1, "source": "registry", "dependencies": { "com.unity.modules.androidjni": "1.0.0", @@ -154,29 +173,86 @@ }, "url": "https://packages.unity.com" }, - "com.unity.test-framework": { - "version": "1.4.6", + "com.unity.services.deployment": { + "version": "1.4.1", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.services.core": "1.12.0", + "com.unity.services.deployment.api": "1.1.2" + }, + "url": "https://packages.unity.com" + }, + "com.unity.services.deployment.api": { + "version": "1.1.2", + "depth": 2, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.services.multiplayer": { + "version": "1.1.8", "depth": 0, "source": "registry", + "dependencies": { + "com.unity.transport": "2.5.0", + "com.unity.collections": "2.2.1", + "com.unity.services.qos": "1.3.0", + "com.unity.services.core": "1.13.0", + "com.unity.services.wire": "1.4.0", + "com.unity.services.deployment": "1.3.0", + "com.unity.nuget.newtonsoft-json": "3.2.1", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.services.authentication": "3.3.3" + }, + "url": "https://packages.unity.com" + }, + "com.unity.services.qos": { + "version": "1.3.0", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.collections": "1.2.4", + "com.unity.services.core": "1.12.4", + "com.unity.nuget.newtonsoft-json": "3.0.2", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.services.authentication": "2.0.0" + }, + "url": "https://packages.unity.com" + }, + "com.unity.services.wire": { + "version": "1.4.0", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.services.core": "1.12.5", + "com.unity.nuget.newtonsoft-json": "3.2.1", + "com.unity.services.authentication": "2.7.4" + }, + "url": "https://packages.unity.com" + }, + "com.unity.test-framework": { + "version": "1.6.0", + "depth": 0, + "source": "builtin", "dependencies": { "com.unity.ext.nunit": "2.0.3", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0" - }, - "url": "https://packages.unity.com" + } }, "com.unity.test-framework.performance": { - "version": "3.0.3", + "version": "3.1.0", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.31", + "com.unity.test-framework": "1.1.33", "com.unity.modules.jsonserialize": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.8.7", + "version": "1.8.9", "depth": 0, "source": "registry", "dependencies": { @@ -188,7 +264,7 @@ "url": "https://packages.unity.com" }, "com.unity.transport": { - "version": "2.4.0", + "version": "2.5.3", "depth": 1, "source": "registry", "dependencies": { @@ -355,7 +431,8 @@ "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.hierarchycore": "1.0.0" + "com.unity.modules.hierarchycore": "1.0.0", + "com.unity.modules.physics": "1.0.0" } }, "com.unity.modules.umbra": {