<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/CollisionFilter/init(group:mask:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation15CollisionFilterV5group4maskAcA0C5GroupV_AGtcfc"
  },
  "title" : "init(group:mask:)"
}
-->

# init(group:mask:)

Creates a collision filter.

```
init(group: CollisionGroup, mask: CollisionGroup)
```

## Parameters

`group`

The collision group identifier.

`mask`

The collision mask defines what objects will collide with
objects using this filter.

## Discussion

Collision filters are created for the collision group specified in the
`group` parameter. The `mask` parameter defines which objects will
collide with the objects that use this filter. Because
[`CollisionGroup`](/documentation/RealityKit/CollisionGroup) conforms to
<doc://com.apple.documentation/documentation/Swift/OptionSet>, you can
specify any combination of collision groups in the `mask` parameter by
using the various
<doc://com.apple.documentation/documentation/Swift/OptionSet> methods
like `CollisionGroup/union(_:)`, `CollisionGroup/subtracting(_:)`,
and `CollisionGroup/intersection(_:)`. Entities from any group
contained in `mask` will collide with entities using this filter, while
those not contained by `mask` will not.

To combine multiple groups into a filter, use the
`CollisionGroup/union(_:)` method, like this:

```swift
let groupA = CollisionGroup(rawValue: 1 << 0)
let groupB = CollisionGroup(rawValue: 1 << 1)
let groupC = CollisionGroup(rawValue: 1 << 2)

// Create a filter that collides with A and C, but not B
let theFilter = CollisionFilter(group: groupA, mask: groupA.union(groupB))
```

A common use case is to want entities to collide with everything except
one group, or a few groups. In a game, for example, you might not want a
player’s pieces to collide with their own pieces, or you might not want
players on the same team to collide with each other. You can accomplish
that by starting with the [`all`](/documentation/RealityKit/CollisionGroup/all) property, subtracting
the group or groups that you don’t want the entities using this filter
to collide with, like this:

```swift
// Create a filter that collides with everything except B
let notGroupB = CollisionGroup.all.subtracting(groupB)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)