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

# findPath(to:)

Computes and returns a sequence of nodes that represents the lowest-cost graph traversal from this node to the specified node.

```
func findPath(to goalNode: GKGraphNode) -> [GKGraphNode]
```

## Parameters

`goalNode`

The destination node to which to attempt traversal of the graph.

## Return Value

An array of nodes representing a path through the graph in start to end order, or an empty array if no path exists between the specified nodes.

## Discussion

The returned array contains the list of nodes one must traverse in order to follow the selected route, starting with the requested `startNode` object, proceeding along the connections between nodes, and ending with the requested `endNode` object. For graphs whose nodes contain geometry information ([`GKGraphNode2D`](/documentation/GameplayKit/GKGraphNode2D) or [`GKGridGraphNode`](/documentation/GameplayKit/GKGridGraphNode) objects), you can use the information from each node in the array to move a game object along the path (or otherwise present the path to the user). Or, to make an agent (a [`GKAgent`](/documentation/GameplayKit/GKAgent) object) automatically follow the returned path, create a [`GKPath`](/documentation/GameplayKit/GKPath) object with the [`init(graphNodes:radius:)`](/documentation/GameplayKit/GKPath/init(graphNodes:radius:)) initializer.

Calling this method is equivalent to calling the [`GKGraph`](/documentation/GameplayKit/GKGraph) [`findPath(from:to:)`](/documentation/GameplayKit/GKGraph/findPath(from:to:)) method when both nodes are in the same graph. However, when you instead use the [`findPath(to:)`](/documentation/GameplayKit/GKGraphNode/findPath(to:)) method of a specific node, GameplayKit finds a path (if one exists) through connected nodes to the destination node regardless of whether both nodes are contained in the same [`GKGraph`](/documentation/GameplayKit/GKGraph) object. This approach can be useful for connecting graphs that should otherwise be distinct. For example, each major area of your game world might have its own [`GKGraph`](/documentation/GameplayKit/GKGraph) object. When the player is near enough to a new area to move into it, you can connect a node of that area’s graph to the current area’s graph. Then, after the player has left an area behind, you can disconnect its graph and unload related content to save memory.

---

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)