Search Issue Tracker
In Progress
Fixed in 2023.1.20f1, 2023.2.0b17, 2023.3.0a13, 2024.1.0a1
Fix In Review for 2022.3.13f1
Votes
1
Found in
2022.3.0f1
2023.1.0a4
2023.2.0a6
2023.3.0a3
2024.1.0a1
Issue ID
UUM-53717
Regression
No
[Physics2D] No reason why it has to be consecutive vertices in customCollider2D.SetCustomShapes(shapes, vertices) and error is outputted "ArgumentException: An invalid PhysicsShape at index 1 was encountered"
When using the overload of [CustomCollider2D.SetCustomShapes|[https://docs.unity3d.com/ScriptReference/CustomCollider2D.SetCustomShapes.html]] that allows passing two NativeArray of PhysicsShape2D and Vector3 vertices, the physics shapes are constrained to only use consecutive vertice between shapes i.e. no unused vertex are allowed and will produce a console warning and not set the physics shapes.
—
What happened?
[https://forum.unity.com/threads/2d-physics-in-unity-2022-1.1327701/#post-9411431]
How can we reproduce that?
The following code leads to an error: "ArgumentException: An invalid PhysicsShape at index 1 was encountered. The CustomCollider2D was not updated."
{code:java}
var shape = new NativeArray<PhysicsShape2D>(2, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
var vertices = new NativeArray<Vector2>(8, Allocator.Temp);
vertices[0] = new Vector2(1, 1);
vertices[1] = new Vector2(1, 2);
vertices[2] = new Vector2(2, 1);
vertices[3] = new Vector2(2, 2);
vertices[4] = new Vector2(1, 1) * 2;
vertices[5] = new Vector2(1, 2) * 2;
vertices[6] = new Vector2(2, 1) * 2;
vertices[7] = new Vector2(2, 2) * 2;
shapes[0] = new PhysicsShape2D { shapeType = PhysicsShapeType2D.Polygon, vertexStartIndex = 0, vertexCount = 3 };
shapes[1] = new PhysicsShape2D { shapeType = PhysicsShapeType2D.Polygon, vertexStartIndex = 4, vertexCount = 3 };
_customCollider.SetCustomShapes(shapes, vertices);
shapes.Dispose();
vertices.Dispose();
{code}
EDIT: I've created and attached a case demonstrating the issue - Melv.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
Resolution Note (fix version 2023.3.0a13):
Fix for this issue is available on Unity 2023.3.0a13 and above
Resolution Note (fix version 2023.2.0b17):
Fix for this issue is available on Unity 2023.2.0b17 and above
Resolution Note (fix version 2023.1.20f1):
Fix for this issue is available on Unity 2023.1.20f1 and above