From 03f85efd31a120e2157375f17a4b52c84c5a043c Mon Sep 17 00:00:00 2001 From: Martijn Gerkes Date: Wed, 26 Aug 2020 12:57:02 +0100 Subject: [PATCH] Upgrade to entities 0.14.0-preview.18 (#1463) * Upgrade to entities 0.14.0-preview.18 * Fix android * Fix TransformSync using deprecated EntityManager null * Changelog and Upgrade guide * Fix codegen using deprecated methods * Remove unused usings --- CHANGELOG.md | 2 ++ UPGRADE_GUIDE.md | 5 +++ .../TransformInitialisationTest.cs | 2 +- .../Core/UnityEcsViewManagerGenerator.cs | 2 +- .../Utility/PlayerLoopUtils.cs | 33 +------------------ .../Worker/WorkerConnector.cs | 8 ++--- .../io.improbable.gdk.core/package.json | 4 +-- .../WorkerInspector/EntityListData.cs | 14 +++++--- .../HandlePlayerHeartbeatResponseSystem.cs | 2 +- .../TransformSynchronization.cs | 2 +- workers/unity/Packages/manifest.json | 3 +- .../ProjectSettings/ProjectSettings.asset | 3 ++ 12 files changed, 30 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3ce318973..58e20bb8d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Breaking Changes - The minimum supported version of Unity is now 2020.1. [#1459](https://github.com/spatialos/gdk-for-unity/pull/1459) +- Upgraded Unity Entities to 0.14.0-preview.18. [#1463](https://github.com/spatialos/gdk-for-unity/pull/1463) + - Projects now require the `Unity Web Request` built-in package to compile for iOS and Android. ### Added diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index a2bc871bcb..e1c9060c5e 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -6,6 +6,11 @@ In order to use the GDK for Unity `0.4.0`, you will need to upgrade your project to Unity 2020.1. We test against 2020.1.2f1, but any `2020.1.x` version _should_ work. +### Unity Entities 0.14 + +Due to our internal upgrade to Unity Entities `0.14.0-preview.18`, your projects are now required to include the `Unity Web Request` built-in package. +You can find this package in the Unity editor under the `Window -> Package Manager` menu. + ## From `0.3.9` to `0.3.10` ### AuthorityLossImminent support removed diff --git a/workers/unity/Assets/Tests/PlaymodeTests/Correctness/TransformSynchronization/TransformInitialisationTest.cs b/workers/unity/Assets/Tests/PlaymodeTests/Correctness/TransformSynchronization/TransformInitialisationTest.cs index c56c37202a..72693c9e42 100644 --- a/workers/unity/Assets/Tests/PlaymodeTests/Correctness/TransformSynchronization/TransformInitialisationTest.cs +++ b/workers/unity/Assets/Tests/PlaymodeTests/Correctness/TransformSynchronization/TransformInitialisationTest.cs @@ -62,7 +62,7 @@ public IEnumerator Transform_initialises_on_enable_and_resets_on_disable() RequireLifecycleSystem.Update(); Assert.IsFalse(transformSyncBehaviour.enabled); - Assert.IsNull(GetPrivateField(transformSyncBehaviour, "entityManager")); + Assert.AreEqual(GetPrivateField(transformSyncBehaviour, "entityManager"), default(EntityManager)); Assert.IsFalse(GetPrivateField(transformSyncBehaviour, "initialised")); } diff --git a/workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/UnityEcsViewManagerGenerator.cs b/workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/UnityEcsViewManagerGenerator.cs index 981842e57c..20817bf220 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/UnityEcsViewManagerGenerator.cs +++ b/workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/UnityEcsViewManagerGenerator.cs @@ -173,7 +173,7 @@ public void Init(World world) { m.Line(@" var entity = workerSystem.GetEntity(update.EntityId); -if (!dataFromEntity.Exists(entity)) +if (!dataFromEntity.HasComponent(entity)) { return; } diff --git a/workers/unity/Packages/io.improbable.gdk.core/Utility/PlayerLoopUtils.cs b/workers/unity/Packages/io.improbable.gdk.core/Utility/PlayerLoopUtils.cs index 3a63ea0d79..cd4b301d77 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/Utility/PlayerLoopUtils.cs +++ b/workers/unity/Packages/io.improbable.gdk.core/Utility/PlayerLoopUtils.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using Unity.Entities; using UnityEngine; -using UnityEngine.LowLevel; namespace Improbable.Gdk.Core { @@ -72,38 +70,9 @@ public static void ResolveSystemGroups(World world) type == typeof(PresentationSystemGroup)) { var groupSystem = system as ComponentSystemGroup; - groupSystem.SortSystemUpdateList(); + groupSystem.SortSystems(); } } } - - public static void RemoveFromPlayerLoop(World world) - { - var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); - - //Reflection to get world from PlayerLoopSystem - var wrapperType = - typeof(ScriptBehaviourUpdateOrder).Assembly.GetType( - "Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelegateWrapper"); - var systemField = wrapperType.GetField("m_System", BindingFlags.NonPublic | BindingFlags.Instance); - - for (var i = 0; i < playerLoop.subSystemList.Length; ++i) - { - ref var playerLoopSubSystem = ref playerLoop.subSystemList[i]; - playerLoopSubSystem.subSystemList = playerLoopSubSystem.subSystemList.Where(s => - { - if (s.updateDelegate != null && s.updateDelegate.Target.GetType() == wrapperType) - { - var targetSystem = systemField.GetValue(s.updateDelegate.Target) as ComponentSystemBase; - return targetSystem.World != world; - } - - return true; - }).ToArray(); - } - - // Update PlayerLoop - ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop); - } } } diff --git a/workers/unity/Packages/io.improbable.gdk.core/Worker/WorkerConnector.cs b/workers/unity/Packages/io.improbable.gdk.core/Worker/WorkerConnector.cs index 8c1f97e4f0..4f44266f3c 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/Worker/WorkerConnector.cs +++ b/workers/unity/Packages/io.improbable.gdk.core/Worker/WorkerConnector.cs @@ -2,16 +2,12 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Improbable.Worker.CInterop; -using Improbable.Worker.CInterop.Alpha; using Unity.Entities; -using UnityEditor; using UnityEngine; -using UnityEngine.LowLevel; namespace Improbable.Gdk.Core { @@ -105,7 +101,7 @@ protected async Task Connect(IConnectionHandlerBuilder builder, ILogDispatcher l // Update PlayerLoop PlayerLoopUtils.ResolveSystemGroups(Worker.World); - ScriptBehaviourUpdateOrder.UpdatePlayerLoop(Worker.World, PlayerLoop.GetCurrentPlayerLoop()); + ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(Worker.World); } catch (Exception) { @@ -251,7 +247,7 @@ private void RemoveFromPlayerLoop() { // Remove root systems from the disposing world from the PlayerLoop // This only affects the loop next frame - PlayerLoopUtils.RemoveFromPlayerLoop(Worker.World); + ScriptBehaviourUpdateOrder.RemoveWorldFromCurrentPlayerLoop(Worker.World); } } diff --git a/workers/unity/Packages/io.improbable.gdk.core/package.json b/workers/unity/Packages/io.improbable.gdk.core/package.json index f46dc8f7f9..649429451b 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/package.json +++ b/workers/unity/Packages/io.improbable.gdk.core/package.json @@ -9,6 +9,6 @@ "io.improbable.worker.sdk": "0.3.10", "io.improbable.gdk.tools": "0.3.10", "io.improbable.gdk.testutils": "0.3.10", - "com.unity.entities": "0.9.1-preview.15" + "com.unity.entities": "0.14.0-preview.18" } -} \ No newline at end of file +} diff --git a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/EntityListData.cs b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/EntityListData.cs index 1805393f63..e32cfd9c4c 100644 --- a/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/EntityListData.cs +++ b/workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/EntityListData.cs @@ -41,12 +41,16 @@ public void SetNewWorld(World newWorld) { fullData.Clear(); FilteredData.Clear(); - query?.Dispose(); + + if (query != default) + { + query.Dispose(); + } if (newWorld == null) { world = null; - query = null; + query = default; return; } @@ -65,10 +69,10 @@ public void RefreshData() using (refreshDataMarker.Auto()) { fullData.Clear(); - var spatialOSComponentType = world.EntityManager.GetArchetypeChunkComponentType(true); + var spatialOSComponentType = world.EntityManager.GetComponentTypeHandle(true); var metadataComponentType = - world.EntityManager.GetArchetypeChunkComponentType(true); - var ecsEntityType = world.EntityManager.GetArchetypeChunkEntityType(); + world.EntityManager.GetComponentTypeHandle(true); + var ecsEntityType = world.EntityManager.GetEntityTypeHandle(); using (var chunks = query.CreateArchetypeChunkArray(Allocator.TempJob)) { diff --git a/workers/unity/Packages/io.improbable.gdk.playerlifecycle/Systems/PlayerHeartbeat/HandlePlayerHeartbeatResponseSystem.cs b/workers/unity/Packages/io.improbable.gdk.playerlifecycle/Systems/PlayerHeartbeat/HandlePlayerHeartbeatResponseSystem.cs index f1553a3e8c..956d4aea9b 100644 --- a/workers/unity/Packages/io.improbable.gdk.playerlifecycle/Systems/PlayerHeartbeat/HandlePlayerHeartbeatResponseSystem.cs +++ b/workers/unity/Packages/io.improbable.gdk.playerlifecycle/Systems/PlayerHeartbeat/HandlePlayerHeartbeatResponseSystem.cs @@ -44,7 +44,7 @@ protected override void OnUpdate() { ref readonly var response = ref responses[i]; var spatialId = response.EntityId; - if (!workerSystem.TryGetEntity(spatialId, out var entity) || !heartbeats.Exists(entity)) + if (!workerSystem.TryGetEntity(spatialId, out var entity) || !heartbeats.HasComponent(entity)) { continue; } diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformSynchronization.cs b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformSynchronization.cs index 4cd103c1af..4f7198220a 100644 --- a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformSynchronization.cs +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformSynchronization.cs @@ -79,7 +79,7 @@ private void OnDisable() StopAllCoroutines(); RemoveStrategies(); - entityManager = null; + entityManager = default; workerType = null; initialised = false; } diff --git a/workers/unity/Packages/manifest.json b/workers/unity/Packages/manifest.json index 97a7d108f5..43eba0acc8 100644 --- a/workers/unity/Packages/manifest.json +++ b/workers/unity/Packages/manifest.json @@ -21,7 +21,8 @@ "com.unity.modules.imgui": "1.0.0", "com.unity.modules.physics": "1.0.0", "com.unity.modules.ui": "1.0.0", - "com.unity.modules.uielements": "1.0.0" + "com.unity.modules.uielements": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" }, "registry": "https://packages.unity.com" } diff --git a/workers/unity/ProjectSettings/ProjectSettings.asset b/workers/unity/ProjectSettings/ProjectSettings.asset index cfa5f67182..b5b544633f 100644 --- a/workers/unity/ProjectSettings/ProjectSettings.asset +++ b/workers/unity/ProjectSettings/ProjectSettings.asset @@ -584,6 +584,7 @@ PlayerSettings: ps4ShareFilePath: ps4ShareOverlayImagePath: ps4PrivacyGuardImagePath: + ps4ExtraSceSysFile: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: @@ -626,6 +627,8 @@ PlayerSettings: ps4disableAutoHideSplash: 0 ps4videoRecordingFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0 + ps4CompatibilityPS5: 0 + ps4GPU800MHz: 1 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] ps4attribVROutputEnabled: 0