# Feature Flag Decision

A Feature Flag has two states: on and off. Different features are configured for each state.\
When a user accesses a feature with a Feature Flag applied, the SDK must be able to return either the on or off state. You can use the Hackle SDK to handle this state decision.

{% hint style="warning" %}
Unity SDK is built on top of Android and iOS SDKs.\
In Unity Editor, false (off state) is returned.
{% endhint %}

## IsFeatureOn

Pass the **Feature Key** to the `IsFeatureOn()` method to receive the state result for the user. Then implement logic based on the state.

In the example code below, Feature Key 42 is passed.

```csharp
// Determines the user's state for the Feature Flag with Feature Key 42.
// Returns false (off state) if a decision cannot be made.
bool isFeatureOn = hackle.IsFeatureOn(42);

if (isFeatureOn) {
    // ON feature
} else {
    // OFF feature
}
```

## FeatureFlagDetail

The `FeatureFlagDetail()` method works the same as `IsFeatureOn()` but additionally provides the reason for the state decision. This is useful for verifying that Override is working correctly or when the result proportion seems inconsistent with the configured Traffic Allocation.

You must pass the Feature Key as a parameter. In the example code below, Feature Key 42 is passed.

```csharp
// Feature Flag Decision detail
HackleFeatureFlagDecision decision = hackle.FeatureFlagDetail(42);

// Feature on/off status
bool isFeatureOn = decision.isOn;

// Decision reason
string reason = decision.reason;
```

The decision reason is returned in a format such as **`SDK_NOT_READY`**. Refer to the table below for details.

<table><thead><tr><th width="233.71875">Decision Reason</th><th width="370.8046875">Description</th><th>Distribution Result</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td>The SDK is not ready to use.<br>(e.g., initialization attempted with an invalid SDK Key)</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_NOT_FOUND</code></td><td>No Feature Flag was found for the provided Feature Key.<br>The Feature Key may be incorrect, or the Feature Flag may be archived.</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_INACTIVE</code></td><td>The Feature Flag is in the off state.</td><td>Default state<br>(off)</td></tr><tr><td><code>INDIVIDUAL_TARGET_MATCH</code></td><td>Matched by Individual Targeting.</td><td>State configured by<br>Individual Targeting</td></tr><tr><td><code>TARGET_RULE_MATCH</code></td><td>Matched by User Targeting.</td><td>State configured by User Targeting</td></tr><tr><td><code>DEFAULT_RULE</code></td><td>Did not match either Individual Targeting or User Targeting.</td><td>State configured by<br>default rule</td></tr><tr><td><code>EXCEPTION</code></td><td>An unknown error occurred.</td><td>Default state<br>(off)</td></tr></tbody></table>

## Feature Flag Parameters

* You can also receive the parameter values for the state decision through the `FeatureFlagDetail()` method.
* You can use the `GetBoolean()`, `GetDouble()`, `GetInt()`, `GetLong()`, and `GetString()` methods to retrieve the parameter values configured in the Feature Flag screen. If you change values in the Feature Flag parameter settings screen, the updated values are applied in the code.
* Since parameter values configured in the Hackle Feature Flag screen are stored as key-value pairs, use the methods below according to the parameter type to retrieve the configured values.
* You can dynamically update values in the Feature Flag parameter configuration screen.

### GetString

* Returns parameter values configured as STRING or JSON type.
* Returns the value configured for False or True based on the state decision.

```csharp
HackleFeatureFlagDecision decsision = hackle.FeatureFlagDetail(42, "ae03e1adf");

string strValue = decsision.GetString("parameter_key_string_type", "defaultValue");
string jsonValue = decsision.GetString("parameter_key_json_type", "{}");
```

### GetInt

* Returns parameter values configured as Number type as an Int.
* Returns the value configured for False or True based on the state decision.

```csharp
HackleFeatureFlagDecision decsision = hackle.FeatureFlagDetail(42, "ae03e1adf");

int intValue = decsision.GetInt("parameter_key_number_type", 0);
```

### GetDouble

* Returns parameter values configured as Number type as a Double.
* Returns the value configured for False or True based on the state decision.

```csharp
HackleFeatureFlagDecision decsision = hackle.FeatureFlagDetail(42, "ae03e1adf");

double doubleValue = decsision.GetDouble("parameter_key_number_type", 0.0);
```

### GetLong

* Returns parameter values configured as Number type as a Long.
* Returns the value configured for False or True based on the state decision.

```csharp
HackleFeatureFlagDecision decsision = hackle.FeatureFlagDetail(42, "ae03e1adf");

long longValue = decsision.GetLong("parameter_key_number_type", 0);
```

### GetBoolean

* Returns parameter values configured as Boolean type.
* Returns the value configured for False or True based on the state decision.

```csharp
HackleFeatureFlagDecision decsision = hackle.FeatureFlagDetail(42, "ae03e1adf");

bool boolValue = decsision.GetBoolean("parameter_key_boolean_type", false);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/unity/unity-feature-flag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
