<!--
{
  "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/init(fromGridStartingAt:width:height:diagonalsAllowed:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKGridGraph(im)initFromGridStartingAt:width:height:diagonalsAllowed:"
  },
  "title" : "init(fromGridStartingAt:width:height:diagonalsAllowed:)"
}
-->

# init(fromGridStartingAt:width:height:diagonalsAllowed:)

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

```
init(fromGridStartingAt position: vector_int2, width: Int32, height: Int32, diagonalsAllowed: Bool)
```

## Parameters

`position`

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

`width`

The number of possible x-coordinates in the grid.

`height`

The number of possible y-coordinates in the grid.

`diagonalsAllowed`

<doc://com.apple.documentation/documentation/Swift/true> to connect nodes in the grid to their diagonal neighbors; <doc://com.apple.documentation/documentation/Swift/false> to connect nodes only to their horizontal and vertical neighbors.

## Return Value

A new grid graph.

## Discussion

All connections created through this method are bidirectional.

---

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)