---
title: "setAttribute(_:forKey:)"
framework: scenekit
role: symbol
role_heading: Instance Method
path: "scenekit/scnscene/setattribute(_:forkey:)"
---

# setAttribute(_:forKey:)

Sets a scene attribute for the specified key.

## Declaration

```swift
func setAttribute(_ attribute: Any?, forKey key: String)
```

## Parameters

- `attribute`: An object that specifies the value of the attribute to be written.
- `key`: One of the constants described in doc://com.apple.scenekit/documentation/SceneKit/scene-attributes that identifies the attribute to be written.

## See Also

### Managing Scene Attributes

- [attribute(forKey:)](scenekit/scnscene/attribute(forkey:).md)
- [SCNScene.Attribute](scenekit/scnscene/attribute.md)
