A bitmask used to define the collision group to which an entity belongs.
Use collision groups along with ``CollisionFilter`` to define custom
collision properties for entities in your scene and to control which entities
collide with which others. By default, all entities that participate in the physics
simulation collide with all other participating entities. There are times,
however, when you need certain entities to not collide with certain other
entities, and that’s where collision groups and filters come into play.
Create individual collision groups using raw bit flag values, like this:
```swift
let redGroup = CollisionGroup(rawValue: 1 << 0)
let blueGroup = CollisionGroup(rawValue: 1 << 1)
let greenGroup = CollisionGroup(rawValue: 1 << 2)
let yellowGroup = CollisionGroup(rawValue: 1 << 3)
```
Because ``CollisionGroup`` conforms to
<doc://com.apple.documentation/documentation/swift/optionset>, this allows
you to create aggregate groups that encompass multiple individual collision
groups, like so:
```swift
let blueAndRedGroup = redGroup.union(blueGroup)
let greenAndYellowGroup = greenGroup.union(yellowGroup)
```
You can also define groups that have all entities except those in specific
groups. In a game, for example, you might want to turn off collisions
between members of the same team or between pieces owned by the same player.
This is what creating that kind of filter would look like:
```swift
let allButRedGroup = CollisionGroup.all.subtracting(redGroup)
```
Collision groups aren’t assigned directly to entities. Instead, you create a
``CollisionFilter`` for the group, and then assign that filter to all the
entities you wish to include in its group. The collision filter’s mask
defines which objects the entities in this group collide with, and all
entities that share the same filter are part of the same collision group.
```swift
let allButRedFilter = CollisionFilter(group: redGroup, mask: allButRedGroup)
redTeamPlayer1.collision?.filter = allButRedFilter
```
Members (5)
get · iOS 13.4+
sceneUnderstanding
TypeScript
get sceneUnderstanding(): CollisionGroup
Swift declaration
static let sceneUnderstanding: CollisionGroup
The default collision group for scene-understanding meshes.
See <doc://com.apple.documentation/documentation/realitykit/realitykit-scene-understanding> for usage and platform availability of ``SpatialTrackingSession/Configuration/SceneUnderstandingCapability``
and ``ARView/Environment/SceneUnderstanding``.
See <doc://com.apple.documentation/documentation/realitykit/realitykit-scene-understanding> for a complete overview of scene-understanding functionality.
get · iOS 13.0+
all
TypeScript
get all(): CollisionGroup
Swift declaration
static let all: CollisionGroup
The collision group that represents all groups.
get · iOS 13.0+
default
TypeScript
get default(): CollisionGroup
Swift declaration
static let `default`: CollisionGroup
The default collision group for objects.
If no ``CollisionFilter`` is assigned to an entity, that entity will be
part of this default collision group.
init · iOS 13.0+
init
TypeScript
init(rawValue: number): CollisionGroup
Swift declaration
init(rawValue: UInt32)
Creates a collision group from a raw value.
This initializer succeeds even if the value passed as `rawValue`
exceeds the static properties declared as part of the option set.
Usually, you will want to create each collision groups setting a
different bit flag for each value, so that multiple individual groups
can be combined using
<doc://com.apple.documentation/documentation/swift/optionset> methods.
Here is an example of creating four collision groups using different
bitflag values for each one.
```swift
let redGroup = CollisionGroup(rawValue: 1 << 0)
let blueGroup = CollisionGroup(rawValue: 1 << 1)
let greenGroup = CollisionGroup(rawValue: 1 << 2)
let yellowGroup = CollisionGroup(rawValue: 1 << 3)
```
- Parameters:
- rawValue: The raw value of the option set to create. Each bit of
rawValue potentially represents an element of the option set, though raw
values may include bits that are not defined as distinct values of the
OptionSet type.
get · iOS 13.0+
rawValue
TypeScript
getRawValue($self: CollisionGroup): number
Swift declaration
let rawValue: UInt32
The corresponding value of the raw type.
A new instance initialized with `rawValue` will be equivalent to this
instance. For example:
enum PaperSize: String {
case A4, A5, Letter, Legal
}
let selectedSize = PaperSize.Letter
print(selectedSize.rawValue)
// Prints "Letter"
print(selectedSize == PaperSize(rawValue: selectedSize.rawValue)!)
// Prints "true"