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

# update(deltaTime:)

Tells the current state object to perform per-frame updates.

```
func update(deltaTime sec: TimeInterval)
```

## Parameters

`sec`

The time step to use for any time-dependent actions performed by this method (typically, the elapsed time since the previous call to this method).

## Discussion

When you call this method, the state machine sends the [`update(deltaTime:)`](/documentation/GameplayKit/GKState/update(deltaTime:)) message to its [`currentState`](/documentation/GameplayKit/GKStateMachine/currentState) object. In that method, your custom [`GKState`](/documentation/GameplayKit/GKState) subclasses can do work that needs to be done periodically while the machine is in a specific state. Typically, you call this method once for every frame your game processes or renders—such as in the <doc://com.apple.documentation/documentation/SpriteKit/SKScene/update(_:)> method of a SpriteKit scene or the <doc://com.apple.documentation/documentation/SceneKit/SCNSceneRendererDelegate/renderer(_:updateAtTime:)> method of a SceneKit render delegate. If your game uses Entity-Component design (see [Entities and Components](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/EntityComponent.html#//apple_ref/doc/uid/TP40015172-CH6) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172)), you can call this method from the [`update(deltaTime:)`](/documentation/GameplayKit/GKComponent/update(deltaTime:)) method of a [`GKComponent`](/documentation/GameplayKit/GKComponent) subclass.

Examples of per-frame state updates include:

- A state machine for an enemy character might have Idle and Chase states. The Chase state’s update method might check the location of the player character and move the enemy character in that direction.
- A state machine for an automated turret might have Ready, Firing, and Cooldown states. The Ready state’s update method might look for nearby enemies to attack and transition to the Firing state upon finding one. The Cooldown state’s update method might track the elapsed time since entering that state and transition to the Ready state after a specific amount of time has passed.
- A state machine that runs a game’s overall UI might have Menu, Playing, Paused, and GameOver states. The Playing state’s update method might delegate to per-frame update methods in other entities that drive gameplay.

---

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)