Returns the cost to travel from this node to the specified, directly connected, node.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
A node from this node’s
The real cost of travel along the specified connection; higher values indicate higher cost.
GKGraph class uses this method in pathfinding between nodes—the
find method finds the lowest-cost path between a specified pair of nodes. For the
GKGraph base class, the cost of travel along any connection is 1, so the
find method simply counts connections, finding the path that involves traveling through the fewest number of nodes. Because the subclasses
GKGrid add geometry information to each node, those classes’ implementation of this method calculates the distance between nodes in 2D space, and the
find method finds the path with the minimum total distance traveled.
Subclasses can implement this method to add other information to the cost. For example, a game might use higher costs to represent travel through regions of a map that are difficult for a character to traverse.