<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKAgentDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(pl)GKAgentDelegate"
  },
  "title" : "GKAgentDelegate"
}
-->

# GKAgentDelegate

Implement this protocol to synchronize the state of an agent with its visual representation in your game.

```
protocol GKAgentDelegate : NSObjectProtocol
```

## Overview

A [`GKAgent`](/documentation/GameplayKit/GKAgent) object simulates its own movement according to constraints and goals. Use this protocol to manage an external object related to the agent, such as the sprite or 3D object that provides that agent’s visual representation in your game.

You can synchronize with an agent in either or both directions:

- To update a visual representation based on the latest data from the agent simulation, implement the [`agentDidUpdate(_:)`](/documentation/GameplayKit/GKAgentDelegate/agentDidUpdate(_:)) method. In this method you can read the [`position`](/documentation/GameplayKit/GKAgent2D/position) and [`rotation`](/documentation/GameplayKit/GKAgent2D/rotation) properties of the agent (as a [`GKAgent2D`](/documentation/GameplayKit/GKAgent2D) or [`GKAgent3D`](/documentation/GameplayKit/GKAgent3D) object) and set the corresponding attributes of whatever object provides the agent’s visual representation.
- To update the agent simulation with data from an external source—for example, if the game object corresponding to an agent is also affected by a physics engine such as those used in SpriteKit and SceneKit—implement the [`agentWillUpdate(_:)`](/documentation/GameplayKit/GKAgentDelegate/agentWillUpdate(_:)) method. In this method you can set the [`position`](/documentation/GameplayKit/GKAgent2D/position) and [`rotation`](/documentation/GameplayKit/GKAgent2D/rotation) properties of the agent (as a [`GKAgent2D`](/documentation/GameplayKit/GKAgent2D) or [`GKAgent3D`](/documentation/GameplayKit/GKAgent3D) object) so that the next simulation step will take your changes to those properties into account.

> Tip:
> If you use the ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKSKNodeComponent`` class to manage the relationship between an entity and a SpriteKit node,  set your ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKSKNodeComponent`` instance as the delegate for that entity’s agent, and GameplayKit will automatically synchronize the agent and its SpriteKit representation.

To learn more about using goals and agents, see [Agents, Goals, and Behaviors](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/Agent.html#//apple_ref/doc/uid/TP40015172-CH8) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

## Topics

### Synchronizing with Agents

[`-  agentWillUpdate:`](/documentation/GameplayKit/GKAgentDelegate/agentWillUpdate(_:))

Tells the delegate that an agent is about to perform its next simulation step.

[`-  agentDidUpdate:`](/documentation/GameplayKit/GKAgentDelegate/agentDidUpdate(_:))

Tells the delegate that an agent has just performed a simulation step.

## Relationships

### Conforming Types

[`GKSCNNodeComponent`](/documentation/GameplayKit/GKSCNNodeComponent)

[`GKSKNodeComponent`](/documentation/GameplayKit/GKSKNodeComponent)

### Inherits From

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

---

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)