<!--
{
  "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(predicate:attribute:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKDecisionNode(im)createBranchWithPredicate:attribute:"
  },
  "title" : "createBranch(predicate:attribute:)"
}
-->

# createBranch(predicate:attribute:)

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

```
func createBranch(predicate: NSPredicate, attribute: any NSObjectProtocol) -> Self
```

## Parameters

`predicate`

The predicate against which to test this node’s attribute.

`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 `predicate` parameter is a predicate for testing values corresponding to this node’s attribute, so this method is useful for questions whose answers involve passing a threshold value, matching a substring, matching an element in a set, or some more complex test. (If a question has a few specific answer values, see the [`createBranch(value:attribute:)`](/documentation/GameplayKit/GKDecisionNode/createBranch(value:attribute:)) method instead.) For example, a strategy combat game might use this method to choose an attack based on the opponent’s health level:

```objc
GKDecisionTree *tree = [[GKDecisionTree alloc] initWithAttribute:@"HP?"];
GKDecisionNode *root = tree.rootNode;
 
[root createBranchWithPredicate:[NSPredicate predicateWithFormat:@"SELF > %@", @20]
                      attribute:@"Shield Bash"];
[root createBranchWithPredicate:[NSPredicate predicateWithFormat:@"SELF <= %@", @20]
                      attribute:@"Mortal Strike"];
```

---

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)