<!--
{
  "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 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKState",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKState"
  },
  "title" : "GKState"
}
-->

# GKState

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

```
class GKState
```

## Overview

The [`GKState`](/documentation/GameplayKit/GKState) abstract class defines the features of state classes to be used with a state machine (a [`GKStateMachine`](/documentation/GameplayKit/GKStateMachine) object). You build a state machine by defining a separate [`GKState`](/documentation/GameplayKit/GKState) subclass for each state of the machine. In each state class, you use the [`isValidNextState(_:)`](/documentation/GameplayKit/GKState/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](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/StateMachine.html#//apple_ref/doc/uid/TP40015172-CH7) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

## Topics

### Creating a State

[`-  init`](/documentation/GameplayKit/GKState/init())

Initializes a state object.

[`+  state`](/documentation/GameplayKit/GKState/state)

Creates a state object with the specified list of valid next states.

### Working with State Machines

[`stateMachine`](/documentation/GameplayKit/GKState/stateMachine)

The state machine that owns this state object.

[`-  isValidNextState:`](/documentation/GameplayKit/GKState/isValidNextState(_:))

Returns a Boolean value indicating whether a state machine currently in this state is allowed to transition into the specified state.

### Handling State Transitions and Updates

[`-  didEnterWithPreviousState:`](/documentation/GameplayKit/GKState/didEnter(from:))

Performs custom actions when a state machine transitions into this state.

[`-  updateWithDeltaTime:`](/documentation/GameplayKit/GKState/update(deltaTime:))

Performs custom actions when a state machine updates while in this state.

[`-  willExitWithNextState:`](/documentation/GameplayKit/GKState/willExit(to:))

Performs custom actions when a state machine transitions out of this state.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)