<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKDecisionNode/createBranch(value:attribute:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKDecisionNode(im)createBranchWithValue:attribute:"
  },
  "title" : "createBranch(value:attribute:)"
}
-->

# createBranch(value:attribute:)

Creates a child node that the decision tree should use when the current node’s attribute has the specified value.

```
func createBranch(value: NSNumber, attribute: any NSObjectProtocol) -> Self
```

## Parameters

`value`

The value for this node’s attribute that should result in following the newly created branch.

`attribute`

The attribute for the child node to create.

## Return Value

The newly created child node.

## Discussion

Use this method to specify a possible result of testing this node’s attribute (that is, an answer for this node’s question). The `attribute` parameter an have either of two kinds of values: if this test produces the decision tree’s final result (or action), the value identifies that action; if the next step in the decision tree is to be another question, the value identifies the next attribute to test (or question to ask).

The `value` parameter is a specific value for this node’s attribute, so this method is useful for questions that must have one of a few specific answers. (If a question has many possible answers, see the [`createBranch(predicate:attribute:)`](/documentation/GameplayKit/GKDecisionNode/createBranch(predicate:attribute:)) method instead.) For example, a strategy combat game might use this method to choose an attack based on the type of opponent:

```swift
 
enum MyEnemyType: Int {
    case Water, Electric, Fire
}
 
let tree = GKDecisionTree(attribute: "HP?")
let root = tree.rootNode
 
root.createBranch(withValue: MyEnemyType.Water.rawValue, attribute: "Water Blast")
root.createBranch(withValue: MyEnemyType.Electric.rawValue, attribute: "Electric Shock"];
root.createBranch(withValue: MyEnemyType.Fire.rawValue, attribute: "Fire"];
```

---

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)