<!--
{
  "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/EntityCollection/insert(_:beforeIndex:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation16EntityCollectionP6insert_11beforeIndexyAA0C0C_SitF"
  },
  "title" : "insert(_:beforeIndex:)"
}
-->

# insert(_:beforeIndex:)

Adds the specified entity to this collection directly before the entity
at the given index. If the entity is already located before the index,
the collection will not change.

```
mutating func insert(_ entity: Entity, beforeIndex index: Int)
```

## Parameters

`entity`

The entity to add to the collection.

`index`

The index of an entity to insert in front
of. If `endIndex` is provided, the entity
will be appended.

## Discussion> Note: This operation can invalidate the index order of any extant entities.

---

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)