---
title: GKObstacleGraph
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkobstaclegraph
---

# GKObstacleGraph

A navigation graph for 2D game worlds that creates a minimal network for precise pathfinding around obstacles.

## Declaration

```swift
class GKObstacleGraph<NodeType> where NodeType : GKGraphNode2D
```

## Overview

Overview You create an obstacle graph with a collection of GKObstacle objects. To use the graph for pathfinding, you add 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 to find routes through the graph. Unlike the related GKMeshGraph class, an obstacle graph creates a minimal network of graph nodes, resulting in paths that are efficient but not smooth. To learn more about graphs and pathfinding, see Pathfinding in GameplayKit Programming Guide.

## Topics

### Creating a Graph

- [init(obstacles:bufferRadius:nodeClass:)](gameplaykit/gkobstaclegraph/init(obstacles:bufferradius:nodeclass:).md)
- [init(obstacles:bufferRadius:)](gameplaykit/gkobstaclegraph/init(obstacles:bufferradius:).md)

### Working with Obstacles

- [obstacles](gameplaykit/gkobstaclegraph/obstacles.md)
- [addObstacles(_:)](gameplaykit/gkobstaclegraph/addobstacles(_:).md)
- [removeObstacles(_:)](gameplaykit/gkobstaclegraph/removeobstacles(_:).md)
- [removeAllObstacles()](gameplaykit/gkobstaclegraph/removeallobstacles().md)
- [nodes(for:)](gameplaykit/gkobstaclegraph/nodes(for:).md)

### Working with Nodes

- [connectUsingObstacles(node:)](gameplaykit/gkobstaclegraph/connectusingobstacles(node:).md)
- [connectUsingObstacles(node:ignoring:)](gameplaykit/gkobstaclegraph/connectusingobstacles(node:ignoring:).md)
- [connectUsingObstacles(node:ignoringBufferRadiusOf:)](gameplaykit/gkobstaclegraph/connectusingobstacles(node:ignoringbufferradiusof:).md)
- [bufferRadius](gameplaykit/gkobstaclegraph/bufferradius.md)

### Locking Node Connections

- [lockConnection(from:to:)](gameplaykit/gkobstaclegraph/lockconnection(from:to:).md)
- [unlockConnection(from:to:)](gameplaykit/gkobstaclegraph/unlockconnection(from:to:).md)
- [isConnectionLocked(from:to:)](gameplaykit/gkobstaclegraph/isconnectionlocked(from:to:).md)

### Instance Methods

- [classForGenericArgument(at:)](gameplaykit/gkobstaclegraph/classforgenericargument(at:).md)

### Initializers

- [init(nodes:)](gameplaykit/gkobstaclegraph/init(nodes:).md)

## Relationships

### Inherits From

- [GKGraph](gameplaykit/gkgraph.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Pathfinding

- [GKGraph](gameplaykit/gkgraph.md)
- [GKMeshGraph](gameplaykit/gkmeshgraph.md)
- [GKGridGraph](gameplaykit/gkgridgraph.md)
- [GKGraphNode](gameplaykit/gkgraphnode.md)
- [GKGraphNode2D](gameplaykit/gkgraphnode2d.md)
- [GKGraphNode3D](gameplaykit/gkgraphnode3d.md)
- [GKGridGraphNode](gameplaykit/gkgridgraphnode.md)
