Search Issue Tracker
Fixed
Fixed in 2022.3.13f1, 2023.1.20f1, 2023.2.0b17, 2023.3.0a13, 7000.0.0a1
Votes
1
Found in
2022.3.0f1
2023.1.0a4
2023.2.0a6
2023.3.0a3
7000.0.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] 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
- Unity CIL Linker fails on Player build when persistent listeners have "<" and ">" in their XML attribute names
- ”Lighting data asset ‘LightingData’ is incompatible with the current Unity version…” warnings are thrown when saving Indoors (URP) and Outdoors (URP) Scenes as Scene Templates
- [iOS] The screen blinks when transitioning from custom to Unity splash screen
- [macOS] ”Ignoring depth surface load action as it is memoryless” warnings are thrown when taking Game View Snapshot
- UI Builder Inspector scrolls back up when changes on an expanded but not fully displayed Inspector tab are saved
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
Resolution Note (fix version 2022.3.13f1):
Fix for this issue is available on Unity 2022.3.13f1 and above