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

# GKPath

A polygonal path that can be followed by an agent.

```
class GKPath
```

## Overview

To make an agent move to or stay within the area defined by a path, create a goal with the [`init(toStayOn:maxPredictionTime:)`](/documentation/GameplayKit/GKGoal/init(toStayOn:maxPredictionTime:)) method; to make an agent traverse along a path, create a goal with the [`init(toFollow:maxPredictionTime:forward:)`](/documentation/GameplayKit/GKGoal/init(toFollow:maxPredictionTime:forward:)) method.

A path can be expressed as a sequence of either 2D points or 3D points. Use the former to create paths for use by [`GKAgent2D`](/documentation/GameplayKit/GKAgent2D) objects, and the latter to create paths for [`GKAgent3D`](/documentation/GameplayKit/GKAgent3D) objects to follow.

> Note:
> The coordinate system in which you express the path’s vertices and radius is arbitrary; you may choose how to map agent positions and sizes into your game scene. It often makes sense to use the same coordinate system as your game engine—for example, when using agents in a SpriteKit-based game, you’d typically specify a path in screen points.

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

### Creating a Path

[`-  initWithPoints:count:radius:cyclical:`](/documentation/GameplayKit/GKPath/initWithPoints:count:radius:cyclical:)

Initializes a path with the specified array of 2D points.

[`+  pathWithPoints:count:radius:cyclical:`](/documentation/GameplayKit/GKPath/pathWithPoints:count:radius:cyclical:)

Creates a path with the specified array of 2D points.

[`-  initWithFloat3Points:count:radius:cyclical:`](/documentation/GameplayKit/GKPath/initWithFloat3Points:count:radius:cyclical:)

Initializes a path with the specified array of 3D points.

[`+  pathWithFloat3Points:count:radius:cyclical:`](/documentation/GameplayKit/GKPath/pathWithFloat3Points:count:radius:cyclical:)

Creates a path with the specified array of 3D points.

[`-  initWithGraphNodes:radius:`](/documentation/GameplayKit/GKPath/init(graphNodes:radius:))

Initializes a path using the positions of the specified graph nodes.

[`+  pathWithGraphNodes:radius:`](/documentation/GameplayKit/GKPath/pathWithGraphNodes:radius:)

Creates a path using the positions of the specified graph nodes.

### Managing a Path’s Attributes

[`radius`](/documentation/GameplayKit/GKPath/radius)

The radius of the path.

[`cyclical`](/documentation/GameplayKit/GKPath/isCyclical)

A Boolean value that determines whether the path loops around on itself (that is, the path’s end point connects to its start point).

### Inspecting a Path’s Shape

[`numPoints`](/documentation/GameplayKit/GKPath/numPoints)

The number of vertices in the path.

[`-  float2AtIndex:`](/documentation/GameplayKit/GKPath/float2(at:))

Returns the 2D point at the specified index in the path’s list of vertices.

[`-  float3AtIndex:`](/documentation/GameplayKit/GKPath/float3(at:))

Returns the 3D point at the specified index in the path’s list of vertices.

[`-  pointAtIndex:`](/documentation/GameplayKit/GKPath/point(at:))

Returns the 2D point at the specified index in the path’s list of vertices.

### Initializers

[`init(points:radius:cyclical:)`](/documentation/GameplayKit/GKPath/init(points:radius:cyclical:)-6qqn4)

[`init(points:radius:cyclical:)`](/documentation/GameplayKit/GKPath/init(points:radius:cyclical:)-2iv4v)

## Relationships

### Conforms To

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

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

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

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

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

[`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)