---
title: "replaceChildNode(_:with:)"
framework: scenekit
role: symbol
role_heading: Instance Method
path: "scenekit/scnnode/replacechildnode(_:with:)"
---

# replaceChildNode(_:with:)

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

## Declaration

```swift
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

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.

## See Also

### Managing the Node Hierarchy

- [parent](scenekit/scnnode/parent.md)
- [childNodes](scenekit/scnnode/childnodes.md)
- [addChildNode(_:)](scenekit/scnnode/addchildnode(_:).md)
- [insertChildNode(_:at:)](scenekit/scnnode/insertchildnode(_:at:).md)
- [removeFromParentNode()](scenekit/scnnode/removefromparentnode().md)
