<!--
{
  "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/GKDecisionTree/findAction(forAnswers:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKDecisionTree(im)findActionForAnswers:"
  },
  "title" : "findAction(forAnswers:)"
}
-->

# findAction(forAnswers:)

Searches the decision tree, following the branches corresponding to each of the specified answers, and returns the resulting action object.

```
func findAction(forAnswers answers: [AnyHashable : any NSObjectProtocol]) -> (any NSObjectProtocol)?
```

## Parameters

`answers`

A dictionary mapping attributes (or questions) to values (or answers to those questions).

## Return Value

The action object resulting from the decision-making process.

## Discussion

Actions can be any type of object relevant to your game; you define action objects when creating the tree. Typically, an action object is a string or simple value type identifying the result of the decision-making process in the context of your game.

In a manually created decision tree, an action is the “attribute” of a leaf node in the tree. That is, if you create a node using a method such as [`createBranch(value:attribute:)`](/documentation/GameplayKit/GKDecisionNode/createBranch(value:attribute:)), and create no further branches from that node, the `attribute` parameter of that node is treated as an action when evaluating the tree.

In an automatically learned decision tree, you provide action values with the [`init(examples:actions:attributes:)`](/documentation/GameplayKit/GKDecisionTree/init(examples:actions:attributes:)) initializer.

> Note:
> If a tree contains random branches (defined with the ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKDecisionNode/createBranch(weight:attribute:)`` method), you do not need to provide an answer for the corresponding attribute when finding an action.

---

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)