RealityCollisions
Organization
Reality-Dev
Skills
RealityKit
Swift
Swift Package Manager
ARKit
An open-source Swift package for defining RealityKit collision groups and assigning collision filters, including collisions with the LiDAR scene mesh.
#RealityKit #Swift #OpenSource
Named Collision Groups
RealityCollisions is an open-source Swift package that makes RealityKit collision filters easier to define and assign.
Instead of using the default filters that collide with everything, you define your groups in an enum and call setNewCollisionFilter(belongsToGroup:canCollideWith:) on an entity. The method writes a CollisionFilter onto the entity, and it creates a collision component when one is missing.
Here is the same collision relationship both ways: an alien that can collide with teammates.
With RealityCollisions
With RealityKit’s native collision groups
Why Use It Instead of Native Setup?
Apple’s native collision workflow gives you the low-level building blocks: collision shapes, a CollisionComponent, and group-and-mask bit fields. That flexibility is useful, but a project with several categories must consistently assign bit positions, construct masks, attach components, generate shapes, and decode event participants throughout the codebase.
RealityCollisions does not replace RealityKit’s physics system. It adds a typed convenience layer on top of it. Your enum becomes the single source of truth for collision categories, while the package converts those cases into RealityKit’s bit masks. This replaces scattered shift operations and raw masks with names such as .teammates, .aliens, and .sceneMesh, making collision intent easier to read and update.
It also removes repetitive setup. setNewCollisionFilter updates an existing component or creates one and recursively generates shapes when needed. Dedicated helpers add or remove collision relationships, opt an entity into LiDAR scene-mesh collisions, create filters for custom components, and translate collision-event entities back into your enum cases.
Built for Selective Collisions
Custom groups through an enum that conforms to
HasCollisionGroups, supporting up to 32 groupsSelective masks so entities collide only with the groups you name, including their own group when you include it
LiDAR scene mesh support through
addCollisionWithLiDARMesh()or a group namedsceneMeshCollision events mapped back to your enum with
fetchCollisionGroups(from:of:)
Installation and Compatibility
Install RealityCollisions through Swift Package Manager using the GitHub repository. It supports iOS, macOS, tvOS, and visionOS, requires Swift 5.9, and is available under the MIT License.