<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ModelSortGroupComponent",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation23ModelSortGroupComponentV"
  },
  "title" : "ModelSortGroupComponent"
}
-->

# ModelSortGroupComponent

A component that configures the rendering order for an entity’s model.

```
struct ModelSortGroupComponent
```

## Overview

Tell the renderer to draw a model on top of another by adding
a `ModelSortGroupComponent` instance to both entities.

A model sort group component gives you control over the rendering
order for entities within the same [`ModelSortGroup`](/documentation/RealityKit/ModelSortGroup).
You can configure the group to render models in a specific order,
even if that order contradicts their relative positions to each other in the
scene.

The scenario below shows a living room scene that has two rectangular cuboids
which overlap and form the shape of a plus symbol.
The blue cuboid is opaque and taller than it is wide.
The red cuboid is transparent and wider than it is tall.





![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, which gives the area where they overlap a purple hue.](images/com.apple.RealityKit/modelsortgroupcomponent-not-set.jpg)

The sections below demonstrate how to change the default behavior by
configuring the properties of the model sort group component.

### Set the draw order

To tell the renderer to draw the red cuboid
before the blue one, add a `ModelSortGroupComponent` instance to both
cuboids.
Then set both component’s [`order`](/documentation/RealityKit/ModelSortGroupComponent/order) property so that the red cuboid’s
component has a smaller value than the blue cuboid’s component.

```swift
let redCuboid = Entity()
let blueCuboid = Entity()

// ...

// Create a group for both cuboids.
let group = ModelSortGroup(depthPass: nil)

let redSortComponent = ModelSortGroupComponent(
    group: group,
    order: 1
)

redCuboid.components.set(redSortComponent)

let blueSortComponent = ModelSortGroupComponent(
    group: group,
    order: 2
)
blueCuboid.components.set(blueSortComponent)
```

The renderer draws the red cuboid first and then doesn’t draw the part of the
blue cuboid where the two cuboids overlap because the nearest face of the
red cuboid in the overlapping area is closer to the camera.





![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, and in the area where they overlap, the blue cuboid isn't visible, which reveals the scene's background through the red one.](images/com.apple.RealityKit/modelsortgroupcomponent-none-redfirst~dark.jpg)

If the renderer instead draws the blue cuboid first,
and the translucent red cuboid second,
the blue cuboid is once again visible in the overlapping area.





![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, which gives the area where they overlap a purple hue.](images/com.apple.RealityKit/modelsortgroupcomponent-none-bluefirst.jpg)

Rendering the blue cuboid produces the same result as if the two cuboids
weren’t in a sort group.

### Set the depth pass

In the examples in the previous section, the renderer draws each model’s
depth and color together, at the same time.

To draw each entity’s color and depth separately, set the [`depthPass`](/documentation/RealityKit/ModelSortGroup/depthPass-swift.property) property of a [`ModelSortGroup`](/documentation/RealityKit/ModelSortGroup) instance, which changes the rendering sequence
for each model in the group that either draws their colors first or their
depths first.

> Tip: You can also set the property with the ``doc://com.apple.RealityKit/documentation/RealityKit/ModelSortGroup/init(depthPass:)`` initializer.

To draw each model’s color on the first pass and then the depth, set the
property to [`ModelSortGroup.DepthPass.postPass`](/documentation/RealityKit/ModelSortGroup/DepthPass-swift.enum/postPass).

```swift
// Draw the color first, depth second.
let group = ModelSortGroup(depthPass: .postPass)
```

|**Red First**                                                                                                                                                                                                                                                  |**Blue First**                                                                                                                                                                                                                                                                                                             |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears behind the blue one.](modelsortgroupcomponent-postpass-redfirst)|![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, which gives the area where they overlap a purple hue.](modelsortgroupcomponent-postpass-bluefirst)|

The [`ModelSortGroup.DepthPass.postPass`](/documentation/RealityKit/ModelSortGroup/DepthPass-swift.enum/postPass) option tells the
renderer to draw entities in reverse order, which gives the effect that the
last model it draws appears in front.

The depth pass [`ModelSortGroup.DepthPass.prePass`](/documentation/RealityKit/ModelSortGroup/DepthPass-swift.enum/prePass) draws each
entity’s depth on the first pass, then their color.

```swift
// Draw the depth first, color second.
let group = ModelSortGroup(depthPass: .prePass)
```

|**Red First**                                                                                                                                                                                                                                                                                                                                                                                   |**Blue First**                                                                                                                                                                                                                                                                                                                                                                                   |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, and in the area where they overlap, the blue cuboid isn’t visible, which reveals the scene’s background through the red one.](modelsortgroupcomponent-prepass-redfirst)|![A screenshot of a living room scene with two rectangular cuboids that overlap. The vertical cuboid is an opaque blue, and the horizontal cuboid is a translucent red. The red cuboid appears in front of the blue one, and in the area where they overlap, the blue cuboid isn’t visible, which reveals the scene’s background through the red one.](modelsortgroupcomponent-prepass-bluefirst)|

The [`ModelSortGroup.DepthPass.prePass`](/documentation/RealityKit/ModelSortGroup/DepthPass-swift.enum/prePass) option tells the renderer
to write the depth buffer for the group’s entities first.
The renderer doesn’t draw the blue cuboid in the overlapping area, regardless
of order, because the red cuboid has a shallower depth in all parts of the
overlapping area.

> Tip: Check out <doc://com.apple.documentation/documentation/visionOS/swift-splash>
> which has an implementation that leverages `ModelSortGroupComponent`.

## Relationships

### Conforms To

[`Component`](/documentation/RealityKit/Component)

---

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)