---
title: "replaceMaterial(at:with:)"
framework: scenekit
role: symbol
role_heading: Instance Method
path: "scenekit/scngeometry/replacematerial(at:with:)"
---

# replaceMaterial(at:with:)

Replaces a material attached to the geometry with another.

## Declaration

```swift
func replaceMaterial(at index: Int, with material: SCNMaterial)
```

## Parameters

- `index`: The index of the attached material to be replaced. important: Raises an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/rangeException) if index is beyond the bounds of the doc://com.apple.scenekit/documentation/SceneKit/SCNGeometry/materials array.
- `material`: The material with which to replace the attached material.

## See Also

### Managing a Geometry’s Materials

- [materials](scenekit/scngeometry/materials.md)
- [firstMaterial](scenekit/scngeometry/firstmaterial.md)
- [material(named:)](scenekit/scngeometry/material(named:).md)
- [insertMaterial(_:at:)](scenekit/scngeometry/insertmaterial(_:at:).md)
- [removeMaterial(at:)](scenekit/scngeometry/removematerial(at:).md)
