<!--
{
  "availability" : [
    "iOS: 8.0.0 - 26.0.0",
    "iPadOS: 8.0.0 - 26.0.0",
    "macCatalyst: 13.1.0 - 26.0.0",
    "macOS: 10.8.0 - 26.0.0",
    "tvOS: 9.0.0 - 26.0.0",
    "visionOS: 1.0.0 - 26.0.0",
    "watchOS: 3.0.0 - 26.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SceneKit",
  "identifier" : "/documentation/SceneKit/SCNNode/replaceChildNode(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SceneKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SCNNode(im)replaceChildNode:with:"
  },
  "title" : "replaceChildNode(_:with:)"
}
-->

# replaceChildNode(_:with:)

Removes a child from the node’s array of children and inserts another node in its place.

```
func replaceChildNode(_ oldChild: SCNNode, with newChild: SCNNode)
```

## Parameters

`oldChild`

The existing child node to be replaced.

`newChild`

The node with which to replace the child node.
  
  > Important:
  > Raises an exception (<doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException>) if `newChild` is `nil`.

## Discussion

If both the `oldChild` and `newChild` nodes are children of the node, calling this method swaps their positions in the array. Note that removing a node from the node hierarchy may result in it being deallocated.

Calling this method results in undefined behavior if the `oldChild` parameter doesn’t refer to a child of this node.

---

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)