CompositeCollider2D
A Collider that can merge other Colliders together.
Read time 11 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
- Inherits from: Collider2D
[RequireComponent(typeof(Rigidbody2D))]public sealed class CompositeCollider2D : Collider2D
Remarks
A CompositeCollider2D merges other Colliders together when their Collider2D.compositeOperation is anything other than Collider2D.CompositeOperation.None, that is, whenever a composite operation is selected.
When a Composite Collider uses a Collider, the Editor will ignore and not show the Collider2D.sharedMaterial, Collider2D.isTrigger & Collider2D.compositeOperation properties. The same properties on the CompositeCollider2D will be used instead. You should set these properties on the Composite Collider to merge all Colliders into the Composite Collider.
NOTE: This Collider2D cannot be disabled/enabled with the Behaviour.enabled property. Any changes to that property will be ignored.
Properties
Property | Description |
|---|---|
| edgeRadius | Controls the radius of all edges created by the Collider. |
| generationType | Specifies when to generate the Composite Collider geometry. |
| geometryType | Specifies the type of geometry the Composite Collider should generate. |
| offsetDistance | Vertices are offset by this distance when compositing multiple physic shapes. Any vertices between shapes within this distance are combined. |
| pathCount | The number of paths in the Collider. |
| pointCount | Gets the total number of points in all the paths within the Collider. |
| useDelaunayMesh | When the value is true, the Collider uses an additional Delaunay triangulation step to produce the Collider mesh. When the value is false, this additional step does not occur. |
| vertexDistance | Controls the minimum distance allowed between generated vertices. |
Methods
Method | Description |
|---|---|
| GenerateGeometry | Regenerates the Composite Collider geometry. |
| GetCompositedColliders | When any Collider2D is using any composite operation other than Collider2D.CompositeOperation.None then it is used by this CompositeCollider2D. |
| GetPath | Gets a path from the Collider by its index. |
| GetPathPointCount | Gets the number of points in the specified path from the Collider by its index. |
Enums
Enum | Description |
|---|---|
| CompositeCollider2D.GenerationType | Specifies when to generate the Composite Collider geometry. |
| CompositeCollider2D.GeometryType | Specifies the type of geometry the Composite Collider generates. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |