---
title: SKAttribute
framework: spritekit
role: symbol
role_heading: Class
path: spritekit/skattribute
---

# SKAttribute

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

## Declaration

```swift
class SKAttribute
```

## Mentioned in

Creating a Custom Fragment Shader

## Overview

Overview To define an attribute for your shader, you create an SKAttribute object with a unique name and data type, which is a SKAttributeType enum. After creating an SKShader object, custom attributes are added to its attributes array. Attribute values are set on the parent node with 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. 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](spritekit/skattributetype.md)

### Initializers

- [init(name:type:)](spritekit/skattribute/init(name:type:).md)
- [init(coder:)](spritekit/skattribute/init(coder:).md)

### Instance Properties

- [name](spritekit/skattribute/name.md)
- [type](spritekit/skattribute/type.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Shaders

- [SKShader](spritekit/skshader.md)
- [SKAttributeValue](spritekit/skattributevalue.md)
- [SKUniform](spritekit/skuniform.md)
