---
title: "lockConnection(from:to:)"
framework: gameplaykit
role: symbol
role_heading: Instance Method
path: "gameplaykit/gkobstaclegraph/lockconnection(from:to:)"
---

# lockConnection(from:to:)

Prevents the specified nodes from being disconnected due to the addition of obstacles.

## Declaration

```swift
func lockConnection(from startNode: NodeType, to endNode: NodeType)
```

## Parameters

- `startNode`: A node in the graph.
- `endNode`: Another node in the graph to which the node startNode is directly connected.

## Discussion

Discussion By default, adding obstacles with the addObstacles(_:) method disconnects pairs of nodes if the direct path between them intersects an obstacle. This behavior ensures that using the findPathBetweenNodes:toNode: method does not result in a path through the graph that crosses obstacles. With certain nodes, such as those you add with the connectUsingObstacles(node:) method to represent the position of a game character or objective, this behavior might not be desirable. For example, if you add an obstacle that overlaps a character’s current position, the character should be able to find a path that exits the obstacle. In this case, use the unlockConnection(from:to:) method to protect the connection between the character’s node and a neighboring node from being automatically destroyed. If you later rearrange nodes so that such protection is no longer necessary, use the unlockConnection(from:to:) method to remove it.

## See Also

### Locking Node Connections

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