<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/SKAttributeValue",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKAttributeValue"
  },
  "title" : "SKAttributeValue"
}
-->

# SKAttributeValue

A container for dynamic shader data associated with a node.

```
class SKAttributeValue
```

## Overview

SpriteKit nodes that are rendered with a custom shader can use [`SKAttributeValue`](/documentation/SpriteKit/SKAttributeValue) objects to pass dynamic values which can change without requiring that shader to be recompiled. An attribute value is passed to a shader using a node’s [`setValue(_:forAttribute:)`](/documentation/SpriteKit/SKNode/setValue(_:forAttribute:)) method using the relevant attribute’s name. For example, given a shader with a [`SKAttributeType.float`](/documentation/SpriteKit/SKAttributeType/float) attribute named `a_radius`:

Listing 1. Creating an attribute

```objc
let attribute = SKAttribute(name: "a_radius", 
                            type: SKAttributeType.float)
```

The following code sets the value of this attribute to `10` and passes it to a [`SKSpriteNode`](/documentation/SpriteKit/SKSpriteNode) object’s shader:

Listing 2. Setting an attribute value

```objc
node.setValue(SKAttributeValue(float: 10), 
              forAttribute: "a_radius")
```

The attribute, `a_radius`, is available as a global floating-point variable within the shader code.

Using this technique, a single shader can be shared across many nodes and each nodes can supply its own attributes. This approach is an alternative to using [`SKUniform`](/documentation/SpriteKit/SKUniform) objects which would require a recompilation for each distinct set of parameters.

## Topics

### Initializers

[`init()`](/documentation/SpriteKit/SKAttributeValue/init())

Creates and initializes a new attribute value object

[`init(float:)`](/documentation/SpriteKit/SKAttributeValue/init(float:))

Creates and initializes a new attribute value object that holds a floating point number.

[`init(vectorFloat2:)`](/documentation/SpriteKit/SKAttributeValue/init(vectorFloat2:))

Creates and initializes a new attribute value object that holds a vector of two floating point numbers.

[`init(vectorFloat3:)`](/documentation/SpriteKit/SKAttributeValue/init(vectorFloat3:))

Creates and initializes a new attribute value object that holds a vector of three floating point numbers.

[`init(vectorFloat4:)`](/documentation/SpriteKit/SKAttributeValue/init(vectorFloat4:))

Creates and initializes a new attribute value object that holds a vector of four floating point numbers.

### Instance Properties

[`floatValue`](/documentation/SpriteKit/SKAttributeValue/floatValue)

The receiver’s floating point value.

[`vectorFloat2Value`](/documentation/SpriteKit/SKAttributeValue/vectorFloat2Value)

The receiver’s value as a vector of two floating-point numbers.

[`vectorFloat3Value`](/documentation/SpriteKit/SKAttributeValue/vectorFloat3Value)

The receiver’s value as a vector of three floating point numbers.

[`vectorFloat4Value`](/documentation/SpriteKit/SKAttributeValue/vectorFloat4Value)

The receiver’s value as a vector of four floating point numbers.



---

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)