<!--
{
  "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/SCNTechnique/setObject(_:forKeyedSubscript:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SceneKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SCNTechnique(im)setObject:forKeyedSubscript:"
  },
  "title" : "setObject(_:forKeyedSubscript:)"
}
-->

# setObject(_:forKeyedSubscript:)

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

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

The `value` parameter should be an object appropriate to the type of the shader symbol being set. For example, use an <doc://com.apple.documentation/documentation/Foundation/NSNumber> object to set the value of a `float` uniform variable, or use an <doc://com.apple.documentation/documentation/Foundation/NSValue> object containing an [`SCNVector3`](/documentation/SceneKit/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:)`](/documentation/SceneKit/SCNTechnique/handleBinding(ofSymbol:using:)) method instead.

If you use the [`handleBinding(ofSymbol:using:)`](/documentation/SceneKit/SCNTechnique/handleBinding(ofSymbol:using:)) method to associate a handler block for a symbol, SceneKit ignores values set for the symbol using the [`setObject(_:forKeyedSubscript:)`](/documentation/SceneKit/SCNTechnique/setObject(_:forKeyedSubscript:)) method.

---

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)