MarkoCrush
MarkoCrush

Reputation: 77

Execution interruption when adding GKObstacleNode to GKObstacleGraph?

I wanted to add an obstacle to the obstacle graph, and interestingly it gives me a runtime error. Is there something that I could be missing or doing that is causing an error?

Playground code

import GameplayKit

let graph = GKObstacleGraph()

let barrier = GKPolygonObstacle(points: [
    float2(x: 200, y: 200),
    float2(x: 500, y: 200)
])

graph.addObstacles([barrier]) // error: Playground execution aborted: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

Upvotes: 0

Views: 62

Answers (1)

Sam Hawksworth
Sam Hawksworth

Reputation: 31

I also encountered this error, the solution I found was to create an SKShapeNode with a path between the two points and then use SKNode.obstacles(fromNodeBounds:) to create the obstacle. Also simply creating GKObstacleGraph() without parameters doesn't seem to work... you have to use GKObstacleGraph(obstacles: [GKPolygonObstacle], bufferRadius: Float, nodeClass: AnyClass) even if you give it an empty array of Obstacles.

Upvotes: 0

Related Questions