<!--
{
  "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/isValidNextState(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKState(im)isValidNextState:"
  },
  "title" : "isValidNextState(_:)"
}
-->

# isValidNextState(_:)

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

```
func isValidNextState(_ stateClass: AnyClass) -> Bool
```

## Parameters

`stateClass`

A custom [`GKState`](/documentation/GameplayKit/GKState) class used in the same state machine as this state.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if a transition into the specified state should be allowed; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

When you call the [`canEnterState(_:)`](/documentation/GameplayKit/GKStateMachine/canEnterState(_:)) or [`enter(_:)`](/documentation/GameplayKit/GKStateMachine/enter(_:)) method of a [`GKStateMachine`](/documentation/GameplayKit/GKStateMachine) object [`currentState`](/documentation/GameplayKit/GKStateMachine/currentState) property is this state, the state machine calls this method to determine whether a transition to the proposed next state is allowed. Override this method in each custom state class you implement to choose which other states should be valid transitions from this state.

> Note:
> GameplayKit may call this method at any time. Your implementation of this method should describe the static relationships between state classes that determine the set of edges in a state machine’s state graph. Do not use this method to conditionally control state transitions—instead, perform such conditional logic before calling a state machine’s ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKStateMachine/enter(_:)`` method.

By restricting the set of valid state transitions, you can use a state machine to enforce invariant conditions in your code. For example, if one state class can be entered only after a state machine has passed through a series of other states, code in that state class can safely assume that any actions performed by those other states have already occurred.

---

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)