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

# MeshInstancesComponent

A component that performs GPU instancing on the model of the same entity.

```
struct MeshInstancesComponent
```

## Overview

RealityKit applies the transform hierarchy of this component’s entity to the individual transforms specified by
[`LowLevelInstanceData`](/documentation/RealityKit/LowLevelInstanceData).
You can think of these instances as sub-entities of the entity you apply this component to,
meaning [`LowLevelInstanceData`](/documentation/RealityKit/LowLevelInstanceData) is in the local space of that same entity.

Due to this transform hierarchy, use the entity’s [`scale`](/documentation/RealityKit/HasTransform/scale), [`position`](/documentation/RealityKit/HasTransform/position), and [`orientation`](/documentation/RealityKit/HasTransform/orientation)
to transform the overall group of instances.
Use the transforms within [`LowLevelInstanceData`](/documentation/RealityKit/LowLevelInstanceData) to transform the individual instances.

To use this component, create a [`LowLevelInstanceData`](/documentation/RealityKit/LowLevelInstanceData) instance and use the
convenience initializer, [`init(mesh:modelID:instances:bounds:)`](/documentation/RealityKit/MeshInstancesComponent/init(mesh:modelID:instances:bounds:)) to create the `MeshInstancesComponent`
directly from a [`MeshResource`](/documentation/RealityKit/MeshResource).

```swift
let entity = try await ModelEntity(named: "robot")

guard let mesh = entity.components[ModelComponent.self]?.mesh else { return }

let instanceCount = 10
let instanceData = try LowLevelInstanceData(instanceCount: instanceCount)

instanceData.withMutableTransforms { transforms in
    for i in 0..<instanceCount {

        let instanceAngle = 2 * .pi * Float(i) / Float(instanceCount)
        let radialTranslation: SIMD3<Float> = [-sin(instanceAngle), cos(instanceAngle), 0] * 2

        // Position each robot around a circle.
        let transform = Transform(
            scale: .one / 10,
            rotation: simd_quatf(angle: instanceAngle, axis: [0, 0, 1]),
            translation: radialTranslation
        )
        transforms[i] = transform.matrix
    }
}

// Instance only the first model.
let modelID = mesh.contents.models.first?.id

// Create the component using the convenience initializer.
let instancesComponent = try MeshInstancesComponent(
    mesh: mesh,
    modelID: modelID,
    instances: instanceData
)
entity.components.set(instancesComponent)

// Place the instance group into position.
entity.position = [0, 0, -1]
```

![A screenshot of ten robots placed around a circle.](images/com.apple.RealityKit/robot-instancing.jpg)

---

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)