Physics Shape Component error on Mesh Collider

Hello,

I just installed unity physics on my project. I also imported the custom physics authoring sample.

I add Physics Shape component. It works with any setting, except Convex Hull and Mesh Colliders (which is what I need, since I’m working with hexagons).

As soon as I choose Mesh or Convex Hull, it doesn’t generate it and it drops the following error constantly

InvalidOperationException: The Unity.Collections.NativeList`1[Unity.Mathematics.float3] GetAabbJob.Points can no longer be accessed, since its owner has been invalidated. You can simply Dispose() the container and create a new one.
Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Unity.Jobs.IJobExtensions.Run[T] (T jobData) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Unity.Physics.Authoring.PhysicsShapeAuthoring.BakePoints (Unity.Collections.NativeArray`1[T] points) (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom/Bodies/PhysicsShapeAuthoring.cs:807)
Unity.Physics.Authoring.PhysicsShapeExtensions.GetBakedConvexProperties (Unity.Physics.Authoring.PhysicsShapeAuthoring shape, Unity.Collections.NativeList`1[T] pointCloud) (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom/Utilities/PhysicsShapeExtensions.cs:294)
Unity.Physics.Editor.PhysicsShapeAuthoringEditor+PreviewMeshData.GetInputHash (Unity.Physics.Authoring.PhysicsShapeAuthoring shape, Unity.Collections.NativeList`1[T] currentPoints, Unity.Collections.NativeArray`1[T] hashedPoints, Unity.Physics.ConvexHullGenerationParameters hashedConvexParameters, Unity.Physics.ConvexHullGenerationParameters& currentConvexProperties) (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom.Editor/Editors/PhysicsShapeAuthoringEditor.cs:241)
Unity.Physics.Editor.PhysicsShapeAuthoringEditor+PreviewMeshData.SchedulePreviewIfChanged (Unity.Physics.Authoring.PhysicsShapeAuthoring shape) (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom.Editor/Editors/PhysicsShapeAuthoringEditor.cs:273)
Unity.Physics.Editor.PhysicsShapeAuthoringEditor.GetPreviewData (Unity.Physics.Authoring.PhysicsShapeAuthoring shape) (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom.Editor/Editors/PhysicsShapeAuthoringEditor.cs:450)
Unity.Physics.Editor.PhysicsShapeAuthoringEditor.OnSceneGUI () (at Assets/Samples/Unity Physics/1.0.16/Custom Physics Authoring/Unity.Physics.Custom.Editor/Editors/PhysicsShapeAuthoringEditor.cs:1098)
(wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,UnityEditor.Editor)
UnityEditor.SceneView.CallOnSceneGUI () (at <78fe3e0b66cf40fc8dbec96aa3584483>:0)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <78fe3e0b66cf40fc8dbec96aa3584483>:0)
UnityEditor.SceneView.DoOnGUI () (at <78fe3e0b66cf40fc8dbec96aa3584483>:0)
UnityEditor.SceneView.OnSceneGUI () (at <78fe3e0b66cf40fc8dbec96aa3584483>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <f6650f702d1247c2a5311a89b759ba03>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render () (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.Panel.UpdateForRepaint () (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <f6650f702d1247c2a5311a89b759ba03>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <d26551307ee24906965335845380d4a1>:0)

The specific line is: “new PhysicsShapeExtensions.GetAabbJob { Points = points, Aabb = aabb }.Run();” in the following context:

        internal unsafe void BakePoints(NativeArray<float3> points)
        {
            var localToShapeQuantized = GetLocalToShapeMatrix();
            using (var aabb = new NativeArray<Aabb>(1, Allocator.TempJob))
            {
                new PhysicsShapeExtensions.GetAabbJob { Points = points, Aabb = aabb }.Run();
                HashableShapeInputs.GetQuantizedTransformations(localToShapeQuantized, aabb[0], out localToShapeQuantized);
            }
            using (var bakedPoints = new NativeArray<float3>(points.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory))
            {
                new BakePointsJob
                {
                    Points = points,
                    LocalToShape = localToShapeQuantized,
                    Output = bakedPoints
                }.Schedule(points.Length, 16).Complete();

                UnsafeUtility.MemCpy(points.GetUnsafePtr(), bakedPoints.GetUnsafePtr(), points.Length * UnsafeUtility.SizeOf<float3>());
            }
        }

Any ideas why this may be happening? I literally just installed it, no modifications or anything. It also fails with a basic cube shape, by the way.

Which version of Unity are you using?

My unity version is 2022.3.16f1

Should I upgrade to version 2023?

No, 2022.3 should be fine. 2023 was less supported than 2022 at some point Entities-wise, so it’s been a good idea to stick with 2022.3 LTS if you don’t need the 2023.x features and prefer stability.

It turns out this is a known issue previously reported on the forum.

Gist of it is, it’s fixed in a preview of 1.2 but 1.0 hasn’t gotten an update with the fix. You could try using 1.2.0-pre.12 of Unity Physics which has those fixes in place. I’ve also attached a copy of the file in question for 1.0 with the fixes listed by daniel-holz.

9682415–1380800–PhysicsShapeAuthoringEditor.cs (54.1 KB)

Brother, your help has been a blessing for my project today. I thank you for your time - may you have a great week. Cheers

Worked like a charm, thank you