Computes and returns a sequence of nodes that represents the shortest traversal of the graph between the specified nodes.
- iOS 9.0+
- macOS 10.11+
- tvOS 9.0+
The node from which to begin traversing the graph.
The destination node to which to attempt traversal of the graph.
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.
The returned array contains the list of nodes one must traverse in order to follow the selected route, starting with the requested
start object, proceeding along the connections between nodes, and ending with the requested
end object. For graphs whose nodes contain geometry information (
GKGrid 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 object) automatically follow the returned path, create a
GKPath object with the
Pathfinding need not be limited to nodes that are contained in the same graph. For example, you might use separate
GKGraph objects to represent distinct areas of your game world—when the player will soon move into an adjoining area, you can connect one or more nodes in the current area’s graph to nodes in the new area’s graph. To find paths between nodes that aren’t necessarily in the same graph, use the
find method of a specific