<!--
{
  "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/SKAttribute",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKAttribute"
  },
  "title" : "SKAttribute"
}
-->

# SKAttribute

A specification for dynamic per-node data used with a custom shader.

```
class SKAttribute
```

## Overview

To define an attribute for your shader, you create an [`SKAttribute`](/documentation/SpriteKit/SKAttribute) object with a unique name and data type, which is a [`SKAttributeType`](/documentation/SpriteKit/SKAttributeType) enum. After creating an [`SKShader`](/documentation/SpriteKit/SKShader) object, custom attributes are added to its [`attributes`](/documentation/SpriteKit/SKShader/attributes) array. Attribute values are set on the parent node with [`setValue(_:forAttribute:)`](/documentation/SpriteKit/SKNode/setValue(_:forAttribute:)) and can change for each execution of a shader without the need for recompilation.

The following listing shows how you can use an attribute to pass the size of a sprite into a shader using an attribute. In this example, `a_sprite_size` is available as a global `vec2` within the GLSL code.

Listing 1. Passing an attribute to a shader.

```objc
let attributeBasedShader = SKShader(fileNamed: "UsingAttributes.fsh")
attributeBasedShader.attributes = [
    SKAttribute(name: "a_sprite_size", type: .vectorFloat2)]

let sprite = SKSpriteNode()
sprite.shader = attributeBasedShader
sprite.size = CGSize(width: 10, height: 10)
let spriteSize = vector_float2(Float(sprite.frame.size.width), 
                               Float(sprite.frame.size.height))
sprite.setValue(SKAttributeValue(vectorFloat2: spriteSize), 
                forAttribute: "a_sprite_size")
```

## Topics

### Constants

[`SKAttributeType`](/documentation/SpriteKit/SKAttributeType)

Options that specify an attribute’s data type.

### Initializers

[`init(name:type:)`](/documentation/SpriteKit/SKAttribute/init(name:type:))

Creates and initializes a new attribute object of a specified type with a name that can be referenced within the shader.

### Instance Properties

[`name`](/documentation/SpriteKit/SKAttribute/name)

The receiver’s name

[`type`](/documentation/SpriteKit/SKAttribute/type)

The data type of the attribute’s value.

### Type Methods

[`attributeWithName:type:`](/documentation/SpriteKit/SKAttribute/attributeWithName:type:)



---

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)