---
title: "setObject(_:forKeyedSubscript:)"
framework: scenekit
role: symbol
role_heading: Instance Method
path: "scenekit/scntechnique/setobject(_:forkeyedsubscript:)"
---

# setObject(_:forKeyedSubscript:)

Sets a value for the specified shader  variable or attribute name, using subscript syntax.

## Declaration

```swift
func setObject(_ obj: Any?, forKeyedSubscript key: any NSCopying)
```

## Parameters

- `obj`: An object containing a new value for the shader symbol.
- `key`: A shader variable or attribute name used in one of the technique’s shader programs.

## Discussion

Discussion The value parameter should be an object appropriate to the type of the shader symbol being set. For example, use an NSNumber object to set the value of a float uniform variable, or use an NSValue object containing an SCNVector3 structure to set the value of a GLSL vec3 uniform variable or a Metal float3 variable. Use this method when you need to set a value infrequently or only once. To update a shader value every time SceneKit renders a frame, use the handleBinding(ofSymbol:using:) method instead. If you use the handleBinding(ofSymbol:using:) method to associate a handler block for a symbol, SceneKit ignores values set for the symbol using the setObject(_:forKeyedSubscript:) method.

## See Also

### Handling Parameters for a Technique’s Shader Programs

- [handleBinding(ofSymbol:using:)](scenekit/scntechnique/handlebinding(ofsymbol:using:).md)
- [subscript(_:)](scenekit/scntechnique/subscript(_:).md)
