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

# GKPolygonObstacle

A polygon-shaped impassable area in a 2D game world.

```
class GKPolygonObstacle
```

## Overview

Polygon obstacles serve two purposes in GameplayKit: You can use polygon obstacles to construct a navigability graph of your game world (a [`GKObstacleGraph`](/documentation/GameplayKit/GKObstacleGraph) object) for use in pathfinding. You can also use polygon obstacles to define regions for agents ([`GKAgent`](/documentation/GameplayKit/GKAgent) objects) to avoid, using the [`GKGoal`](/documentation/GameplayKit/GKGoal) method [`init(toAvoid:maxPredictionTime:)`](/documentation/GameplayKit/GKGoal/init(toAvoid:maxPredictionTime:)-7oslq).

To easily create obstacles for use with a SpriteKit game, create and arrange a set of nodes that define the non-navigable regions of your game world. You can create such nodes programmatically, or use the SpriteKit Scene Editor in Xcode. If you’re already using nodes with physics bodies to keep sprites from entering those regions, you can reuse those nodes. Then, use the <doc://com.apple.documentation/documentation/SpriteKit/SKNode/obstacles(fromNodeBounds:)>, <doc://com.apple.documentation/documentation/SpriteKit/SKNode/obstacles(fromSpriteTextures:accuracy:)>, or <doc://com.apple.documentation/documentation/SpriteKit/SKNode/obstacles(fromNodePhysicsBodies:)> method to generate a set of [`GKPolygonObstacle`](/documentation/GameplayKit/GKPolygonObstacle) objects.

To learn more about both ways of using polygon obstacles, see [Pathfinding](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/Pathfinding.html#//apple_ref/doc/uid/TP40015172-CH3) and [Agents, Goals, and Behaviors](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/Agent.html#//apple_ref/doc/uid/TP40015172-CH8) 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 Polygon Obstacle

[`-  initWithPoints:count:`](/documentation/GameplayKit/GKPolygonObstacle/initWithPoints:count:)

Initializes a polygon obstacle with the specified list of vertices.

[`+  obstacleWithPoints:count:`](/documentation/GameplayKit/GKPolygonObstacle/obstacleWithPoints:count:)

Creates a polygon obstacle with the specified list of vertices.

### Inspecting Vertices

[`vertexCount`](/documentation/GameplayKit/GKPolygonObstacle/vertexCount)

The number of vertices that define the polygon-shaped area of the obstacle.

[`-  vertexAtIndex:`](/documentation/GameplayKit/GKPolygonObstacle/vertex(at:))

Returns the point coordinates of the specified vertex.

### Initializers

[`init(points:)`](/documentation/GameplayKit/GKPolygonObstacle/init(points:))

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

### Inherits From

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

---

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)