<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKMeshGraph",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKMeshGraph"
  },
  "title" : "GKMeshGraph"
}
-->

# GKMeshGraph

A navigation graph for 2D game worlds that creates a space-filling network for smooth pathfinding around obstacles.

```
class GKMeshGraph<NodeType> where NodeType : GKGraphNode2D
```

## Overview

To use a mesh graph for pathfinding, add a collection of [`GKObstacle`](/documentation/GameplayKit/GKObstacle) objects representing impassable areas and [`GKGraphNode2D`](/documentation/GameplayKit/GKGraphNode2D) objects representing points of interest (such as the current position of a game character and the location it needs to find a route to). Then use methods of the superclass [`GKGraph`](/documentation/GameplayKit/GKGraph) to find routes through the graph.

Unlike the related [`GKObstacleGraph`](/documentation/GameplayKit/GKObstacleGraph) class, a mesh graph creates a space-filling network of graph nodes, resulting in paths that are smooth but not the most efficient.

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

[`-  initWithBufferRadius:minCoordinate:maxCoordinate:nodeClass:`](/documentation/GameplayKit/GKMeshGraph/init(bufferRadius:minCoordinate:maxCoordinate:nodeClass:))

Initializes a graph to cover the specified area, using the specified node class.

[`+  graphWithBufferRadius:minCoordinate:maxCoordinate:nodeClass:`](/documentation/GameplayKit/GKMeshGraph/graphWithBufferRadius:minCoordinate:maxCoordinate:nodeClass:)

Creates a graph to cover the specified area, using the specified node class.

[`-  initWithBufferRadius:minCoordinate:maxCoordinate:`](/documentation/GameplayKit/GKMeshGraph/init(bufferRadius:minCoordinate:maxCoordinate:))

Initializes a graph to cover the specified area.

[`+  graphWithBufferRadius:minCoordinate:maxCoordinate:`](/documentation/GameplayKit/GKMeshGraph/graphWithBufferRadius:minCoordinate:maxCoordinate:)

Creates a graph to cover the specified area.

### Working with Obstacles

[`obstacles`](/documentation/GameplayKit/GKMeshGraph/obstacles)

The list of obstacle objects in the graph, each of which describes a polygon-shaped impassable area.

[`-  addObstacles:`](/documentation/GameplayKit/GKMeshGraph/addObstacles(_:))

Adds new obstacles to the graph.

[`-  removeObstacles:`](/documentation/GameplayKit/GKMeshGraph/removeObstacles(_:))

Removes the specified obstacle from the graph.

### Working with Nodes

[`-  connectNodeUsingObstacles:`](/documentation/GameplayKit/GKMeshGraph/connectUsingObstacles(node:))

Adds the specified node to the graph, connecting it to its nearest neighbors without creating connections that pass through obstacles or their buffer regions.

[`bufferRadius`](/documentation/GameplayKit/GKMeshGraph/bufferRadius)

The distance from obstacle edges that should also be considered impassable.

### Managing the Mesh

[`-  triangulate`](/documentation/GameplayKit/GKMeshGraph/triangulate())

Creates or updates the graph with a network of nodes that describes the open space around its obstacles.

[`triangulationMode`](/documentation/GameplayKit/GKMeshGraph/triangulationMode)

A set of options for how to place graph nodes when triangulating the graph.

[`-  triangleAtIndex:`](/documentation/GameplayKit/GKMeshGraph/triangle(at:))

The triangle definition at the specified index.

[`triangleCount`](/documentation/GameplayKit/GKMeshGraph/triangleCount)

The number of triangles in the mesh.

### Constants

[`GKMeshGraphTriangulationMode`](/documentation/GameplayKit/GKMeshGraphTriangulationMode)

Options for how to place graph nodes when generating the graph, used by the [`triangulationMode`](/documentation/GameplayKit/GKMeshGraph/triangulationMode) property.

[`GKTriangle`](/documentation/GameplayKit/GKTriangle)

The definition of a triangle in the mesh, available with the [`triangle(at:)`](/documentation/GameplayKit/GKMeshGraph/triangle(at:)) method.

### Instance Methods

[`-  classForGenericArgumentAtIndex:`](/documentation/GameplayKit/GKMeshGraph/classForGenericArgument(at:))

## Relationships

### Inherits From

[`GKGraph`](/documentation/GameplayKit/GKGraph)

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSCopying`](/documentation/Foundation/NSCopying)

---

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)