CustomCollider2D
Represents a Collider2D that is configured by assigning PhysicsShape2D geometry to it via a PhysicsShapeGroup2D.
Read time 11 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
- Inherits from: Collider2D
public sealed class CustomCollider2D : Collider2D
Remarks
Unlike all other Collider2D which are defined indirectly by controlling geometric parameters such as the size of a Box or the radius of a Circle, here the CustomCollider2D is defined entirely by adding, removing and modifying PhysicsShape2D. This results in a fully customized Collider2D containing an unlimited number of low-level PhysicsShape2D which can represent any type of shape or shapes, or emulate any other existing Collider2D such as the CircleCollider2D, BoxCollider2D, CapsuleCollider2D, EdgeCollider2D, CompositeCollider2D or TilemapCollider2D.
Alongside the customized geometry, there is full support for all existing Collider2D functionality such as triggers, physics materials, queries etc.
When assigning PhysicsShape2D to the CustomCollider2D, you can do so either during Edit mode or Play mode.
When modifying the CustomCollider2D during Edit mode, all assigned PhysicsShape2D and associated vertices will be saved with the Unity Scene. When the Unity Scene is loaded again, the CustomCollider2D will maintain its configuration. In this way, it acts like any other Collider2D that you make changes to during Edit mode. Using this ability, Edit mode authoring scripts can be used to create custom geometry.
When modifing the CustomCollider2D during Play mode, all assigned PhysicsShape2D and associated vertices will be lost when exiting Play mode. This acts like any other Collider2D.
Properties
Property | Description |
|---|---|
| customShapeCount | The total number of custom PhysicsShape2D assigned to the Collider. (Read Only) |
| customVertexCount | The total number of vertices used by the Collider. (Read Only) |
Methods
Method | Description |
|---|---|
| ClearCustomShapes | Deletes all the shapes and associated vertices for those shapes from the Collider. |
| GetCustomShapes | Gets all the physics shapes and vertices in the Collider and places them in the specified arrays. |
| SetCustomShape | Sets a single shape and all associated shape vertices from the specified shape and vertices arrays into the Collider. |
| SetCustomShapes | Sets all the shapes and vertices in the Collider to those represented by the specified arrays. |
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. |