---
title: GKState
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkstate
---

# GKState

The abstract superclass for defining state-specific logic as part of a state machine.

## Declaration

```swift
class GKState
```

## Overview

Overview The GKState abstract class defines the features of state classes to be used with a state machine (a GKStateMachine object). You build a state machine by defining a separate GKState subclass for each state of the machine. In each state class, you use the isValidNextState(_:) method to define which other states are valid for a machine to transition into. State classes provide a place to put state-dependent game logic, such as actions that should happen when entering or exiting a specific state, or per-frame update code that is valid only when in a specific state. For more information about state machines, read State Machines in GameplayKit Programming Guide.

## Topics

### Creating a State

- [init()](gameplaykit/gkstate/init().md)

### Working with State Machines

- [stateMachine](gameplaykit/gkstate/statemachine.md)
- [isValidNextState(_:)](gameplaykit/gkstate/isvalidnextstate(_:).md)

### Handling State Transitions and Updates

- [didEnter(from:)](gameplaykit/gkstate/didenter(from:).md)
- [update(deltaTime:)](gameplaykit/gkstate/update(deltatime:).md)
- [willExit(to:)](gameplaykit/gkstate/willexit(to:).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)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### State Machines

- [GKStateMachine](gameplaykit/gkstatemachine.md)
