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

# GKGridGraph

A navigation graph for 2D game worlds where movement is constrained to an integer grid.

```
class GKGridGraph<NodeType> where NodeType : GKGridGraphNode
```

## Overview

Use this class to generate a graph containing [`GKGridGraphNode`](/documentation/GameplayKit/GKGridGraphNode) objects representing a specified grid. Then use methods of the superclass [`GKGraph`](/documentation/GameplayKit/GKGraph) to find routes through the graph.

To learn more about graphs and pathfinding, see [Pathfinding](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/Pathfinding.html#//apple_ref/doc/uid/TP40015172-CH3) 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 Graph

[`init(fromGridStartingAt:width:height:diagonalsAllowed:nodeClass:)`](/documentation/GameplayKit/GKGridGraph/init(fromGridStartingAt:width:height:diagonalsAllowed:nodeClass:))

Initializes a graph that describes an integer grid with the specified dimensions, using the specified node class.

[`graphFromGridStartingAt:width:height:diagonalsAllowed:nodeClass:`](/documentation/GameplayKit/GKGridGraph/graphFromGridStartingAt:width:height:diagonalsAllowed:nodeClass:)

Creates a graph that describes an integer grid with the specified dimensions, using the specified node class.

[`init(fromGridStartingAt:width:height:diagonalsAllowed:)`](/documentation/GameplayKit/GKGridGraph/init(fromGridStartingAt:width:height:diagonalsAllowed:))

Initializes a graph that describes an integer grid with the specified dimensions.

[`graphFromGridStartingAt:width:height:diagonalsAllowed:`](/documentation/GameplayKit/GKGridGraph/graphFromGridStartingAt:width:height:diagonalsAllowed:)

Creates a graph that describes an integer grid with the specified dimensions.

### Working with Nodes

[`node(atGridPosition:)`](/documentation/GameplayKit/GKGridGraph/node(atGridPosition:))

Returns the node in the graph at the specified grid coordinates.

[`connectToAdjacentNodes(node:)`](/documentation/GameplayKit/GKGridGraph/connectToAdjacentNodes(node:))

Adds the specified node to the graph, connecting it to its nearest neighbors in the grid.

### Inspecting a Graph

[`diagonalsAllowed`](/documentation/GameplayKit/GKGridGraph/diagonalsAllowed)

A Boolean value that indicates whether nodes in the grid are connected to their diagonal neighbors.

[`gridOrigin`](/documentation/GameplayKit/GKGridGraph/gridOrigin)

The lowest x- and y-coordinates that appear in the grid.

[`gridWidth`](/documentation/GameplayKit/GKGridGraph/gridWidth)

The number of possible x-coordinates in the grid.

[`gridHeight`](/documentation/GameplayKit/GKGridGraph/gridHeight)

The number of possible y-coordinates in the grid.

### Instance Methods

[`classForGenericArgument(at:)`](/documentation/GameplayKit/GKGridGraph/classForGenericArgument(at:))



---

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)