Attempts to transition the state machine from its current state to a state of the specified class.
SDKs
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Gameplay
Kit
Declaration
Parameters
stateClass
The class of state into which to attempt a transition.
Return Value
true
if the transition was successful; otherwise false
.
Discussion
You build a state machine by creating a unique GKState
subclass for each distinct state possible for the machine. The is
method of each state object determines which other states a state machine is allowed to transition into from that state. Calling this method first tests whether a transition from the current state to the specified state is valid; if not, this method returns false
.
If a transition is allowed, the state machine sends the will
message to its current state object. Then, the new state object replaces the value of the current
property. Finally, the state machine sends the did
message to the new current state object, and this method returns true
.
A newly created state machine’s current
property is nil
—to choose and enter an initial state, use the enter(_:)
method. In this case, the enter(_:)
call always succeeds.