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

# GKBehavior

A set of goals that together influence the movement of an agent.

```
class GKBehavior
```

## Overview

By combining multiple goals ([`GKGoal`](/documentation/GameplayKit/GKGoal) objects) you can create complex behavior, such as groups of agents  ([`GKAgent`](/documentation/GameplayKit/GKAgent) objects) that move together naturally. To assign a set of goals to an agent, use its [`behavior`](/documentation/GameplayKit/GKAgent/behavior) property.

To learn more about using goals and agents, see [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 Behavior

[`+  behaviorWithGoal:weight:`](/documentation/GameplayKit/GKBehavior/init(goal:weight:))

Creates a behavior with a single goal.

[`+  behaviorWithGoals:`](/documentation/GameplayKit/GKBehavior/init(goals:))

Creates a behavior with the specified goals.

[`+  behaviorWithGoals:andWeights:`](/documentation/GameplayKit/GKBehavior/init(goals:andWeights:))

Creates a behavior with the specified goals and weights.

[`+  behaviorWithWeightedGoals:`](/documentation/GameplayKit/GKBehavior/init(weightedGoals:))

Creates a behavior with the specified mapping of goals to their weights.

### Managing a Behavior’s Set of Goals

[`-  setWeight:forGoal:`](/documentation/GameplayKit/GKBehavior/setWeight(_:for:))

Sets the weight for the specified goal’s influence on agents, adding that goal to the behavior if not already present.

[`-  weightForGoal:`](/documentation/GameplayKit/GKBehavior/weight(for:))

Returns the weight for the specified goal’s influence on agents.

[`-  removeGoal:`](/documentation/GameplayKit/GKBehavior/remove(_:))

Removes the specified goal from the behavior.

[`-  removeAllGoals`](/documentation/GameplayKit/GKBehavior/removeAllGoals())

Removes all goals from the behavior.

[`goalCount`](/documentation/GameplayKit/GKBehavior/goalCount)

The number of goals in the behavior.

### Working with Goals Using Subscript Syntax

[`-  objectForKeyedSubscript:`](/documentation/GameplayKit/GKBehavior/subscript(_:)-2yvko)

Returns the weight associated with the goal specified by subscript syntax.

[`-  setObject:forKeyedSubscript:`](/documentation/GameplayKit/GKBehavior/setObject:forKeyedSubscript:)

Sets the weight for the goal specified by subscript syntax.

[`-  objectAtIndexedSubscript:`](/documentation/GameplayKit/GKBehavior/subscript(_:)-997a9)

Returns the goal at the specified index in the behavior’s list of goals.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Inherited By

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

---

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)