ConvexPolygonShape2D
Filled convex geometry from an ordered contour or a point cloud.
ConvexPolygonShape2D describes a filled convex polygon in local coordinates. A new resource has no vertices. For a collider, assign configured geometry to Shape on CollisionShape2D, which must be a direct child Entity of the required CollisionObject2D.
Choose the input method:
- Points or SetPoints: prepared vertices in boundary order. The contour must be convex and free of self-intersections, with at least three noncollinear finite vertices. Do not pass arbitrarily shuffled points.
- SetPointCloud: unordered points. Computes the outer convex hull; interior points and concavities are discarded. A hull therefore cannot accurately reproduce a silhouette with indentations.
SetPoints retains the supplied order. Physics winding is normalized on a copy, so Points readback can retain either winding. The current SetPointCloud result repeats the first vertex at the end: the checked square cloud produced Points.Length=5 despite having four unique corners. Do not infer unique-corner count from array length.
The C# getter returns a copy. To change one vertex, get Points, edit the array and assign it back. Editing the original array after SetPoints does not change the shape either. The setter emits Changed even for repeated data. GetRect() returns local bounds of all vertices, excluding the resource user’s transform.
Both overload families (array and ReadOnlySpan), copies, winding, hull generation, Changed and direct overlap with a circle inside a square were checked. Unlike a closed ConcavePolygonShape2D, convex geometry is filled. Body dynamics, performance and editor drawing were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ConvexPolygonShape2DConstructor
public ConvexPolygonShape2D();Creates a resource without vertices. Assign a valid convex contour before queries or collider use; the resource itself creates no physics body.
Properties1
PointsProperty
public Vector2[] Points { get; set; }Ordered local vertices of a convex contour. The setter copies data and emits Changed even on repetition; it does not compute a convex hull. The getter returns an independent array in stored order. Internal physics winding normalization does not reorder stored Points. Edit the copy and assign it back to update the shape.
Methods5
GetPointsVector2[]
public Vector2[] GetPoints();Independent copy of stored local vertices. Editing the array does not update the resource; assign edited data through Points or SetPoints.
Vector2[]Independent copy of stored local vertices. Editing the array does not update the resource; assign edited data through Points or SetPoints.
SetPointCloud2 overloads
public void SetPointCloud(Vector2[] pointCloud);Computes the point cloud’s convex hull and passes it to SetPoints. Input order is irrelevant; interior points are discarded and concavities disappear. Supply finite points forming a nondegenerate polygon. The current result repeats its first vertex at the end; Points length is not the number of unique corners. Array and ReadOnlySpan overloads produce the same geometry; input is not retained as a shared mutable buffer.
| Name | Type | Default |
|---|---|---|
pointCloud | Vector2[] | — |
pointCloudUnordered finite points for an outer convex hull; the set must form a polygon of nonzero area. Interior points and concavities are not preserved.
public void SetPointCloud(ReadOnlySpan<Vector2> pointCloud);Computes the point cloud’s convex hull and passes it to SetPoints. Input order is irrelevant; interior points are discarded and concavities disappear. Supply finite points forming a nondegenerate polygon. The current result repeats its first vertex at the end; Points length is not the number of unique corners. Array and ReadOnlySpan overloads produce the same geometry; input is not retained as a shared mutable buffer.
| Name | Type | Default |
|---|---|---|
pointCloud | ReadOnlySpan<Vector2> | — |
pointCloudUnordered finite points for an outer convex hull; the set must form a polygon of nonzero area. Interior points and concavities are not preserved.
SetPoints2 overloads
public void SetPoints(Vector2[] points);Replaces vertices with a prepared convex contour in boundary order and emits Changed, including repeated data. Does not sort a point cloud or turn a concave contour convex. Supply at least three noncollinear finite vertices without self-intersections or zero-length edges. Data is copied; both winding directions support the same geometry. Use SetPointCloud for unordered points.
| Name | Type | Default |
|---|---|---|
points | Vector2[] | — |
pointsPrepared convex contour in boundary order: at least three noncollinear finite vertices, without self-intersections or zero-length edges. Not a point cloud.
public void SetPoints(ReadOnlySpan<Vector2> points);Replaces vertices with a prepared convex contour in boundary order and emits Changed, including repeated data. Does not sort a point cloud or turn a concave contour convex. Supply at least three noncollinear finite vertices without self-intersections or zero-length edges. Data is copied; both winding directions support the same geometry. Use SetPointCloud for unordered points.
| Name | Type | Default |
|---|---|---|
points | ReadOnlySpan<Vector2> | — |
pointsPrepared convex contour in boundary order: at least three noncollinear finite vertices, without self-intersections or zero-length edges. Not a point cloud.