<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/PhysicsJoint/addToSimulation()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation12PhysicsJointPAAE15addToSimulationAA6EntityCyKF"
  },
  "title" : "addToSimulation()"
}
-->

# addToSimulation()

Adds this joint to the simulation.

```
@discardableResult @MainActor func addToSimulation() throws -> Entity
```

## Return Value

The entity that owns the [`PhysicsJointsComponent`](/documentation/RealityKit/PhysicsJointsComponent), which this joint has been added to.

## Discussion

This method looks for an ancestral [`Entity`](/documentation/RealityKit/Entity) that has [`PhysicsJointsComponent`](/documentation/RealityKit/PhysicsJointsComponent)
by traversing upwards from the entity referenced by [`pin0`](/documentation/RealityKit/PhysicsJoint/pin0).

If found, it adds the joint to that ancestor’s [`PhysicsJointsComponent`](/documentation/RealityKit/PhysicsJointsComponent).

The traversal stops when reaching an [`Entity`](/documentation/RealityKit/Entity) with [`PhysicsSimulationComponent`](/documentation/RealityKit/PhysicsSimulationComponent),
or when it cannot traverse up anymore.
In the former case it adds the joint to [`joints`](/documentation/RealityKit/PhysicsJointsComponent/joints).
In the latter case it adds [`PhysicsJointsComponent`](/documentation/RealityKit/PhysicsJointsComponent)
to the first [`Entity`](/documentation/RealityKit/Entity) referenced by the joint, and adds the joint to the newly created [`PhysicsJointsComponent`](/documentation/RealityKit/PhysicsJointsComponent).

> Throws: When the joint contains invalid data.

---

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)