---
title: SKConstraint
framework: spritekit
role: symbol
role_heading: Class
path: spritekit/skconstraint
---

# SKConstraint

A specification for constraining a node’s position or rotation.

## Declaration

```swift
class SKConstraint
```

## Mentioned in

Working with Inverse Kinematics

## Overview

Overview An SKConstraint object describes a mathematical constraint on a node’s position or orientation. You attach constraints to nodes; after a scene processes any actions and physics interactions, it applies constraints attached to nodes in its node tree. Use constraints to ensure that certain relationships are true before the system renders a scene. For example, you might use a constraint to: Change a node’s zRotation property so that it always points at another node or a position in the scene. Keep a node within a specified distance of another node or a point in the scene. Keep a node inside a specified rectangle. Restrict the zRotation property of a node so that it has a more limited rotation range of motion. To use constraints, create an NSArray object that contains one or more constraint objects and assign the array to a node’s constraints property. When the system evaluates a scene, it executes the constraints on a node in the order they appear in the constraints array. You can’t change a constraint after you create it. However, you can selectively disable or enable a constraint by setting its enabled property. You can also use the referenceNode property to convert positions to the referenced coordinate system before applying the constraint.

## Topics

### Creating Position Constraints

- [Creating Position Constraints](spritekit/creating-position-constraints.md)
- [positionX(_:y:)](spritekit/skconstraint/positionx(_:y:).md)
- [positionX(_:)](spritekit/skconstraint/positionx(_:).md)
- [positionY(_:)](spritekit/skconstraint/positiony(_:).md)

### Creating Orientation Constraints

- [Creating a Look-At Constraint](spritekit/creating-a-look-at-constraint.md)
- [orient(to:offset:)](spritekit/skconstraint/orient(to:offset:)-1h1tw.md)
- [orient(to:offset:)](spritekit/skconstraint/orient(to:offset:)-9lq3h.md)
- [orient(to:in:offset:)](spritekit/skconstraint/orient(to:in:offset:).md)
- [zRotation(_:)](spritekit/skconstraint/zrotation(_:).md)

### Creating Distance Constraints

- [distance(_:to:)](spritekit/skconstraint/distance(_:to:)-6507j.md)
- [distance(_:to:)](spritekit/skconstraint/distance(_:to:)-7yk7n.md)
- [distance(_:to:in:)](spritekit/skconstraint/distance(_:to:in:).md)

### Controlling the Coordinate System Where a Constraint is Applied

- [referenceNode](spritekit/skconstraint/referencenode.md)

### Enabling and Disabling a Constraint

- [enabled](spritekit/skconstraint/enabled.md)

### Initializers

- [init(coder:)](spritekit/skconstraint/init(coder:).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)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Constraints

- [SKReachConstraints](spritekit/skreachconstraints.md)
