> For the complete documentation index, see [llms.txt](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/available-api/detection-api.md).

# Detection API

## Set Target To Follow

Assigns a new target for an AI to follow. This will turn the AI into a Pet or Companion AI depending on its [Behavior Type](/emerald-ai-wiki/emerald-components-required/behaviors-component.md).&#x20;

{% hint style="info" %}
**Note:** The optional CopyFactionData parameter will copy the Target to Follow's Faction Data so it will react the same way the follower does to detected targets. This requires the Target to Follow to be another AI (if this condition is not met, this parameter will be ignored). This option is enabled by default.
{% endhint %}

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp"><strong>EmeraldAPI.Detection.SetTargetToFollow(EmeraldSystem EmeraldComponent, Transform Target, bool CopyFactionData = true)
</strong></code></pre>

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Detection.SetTargetToFollow(EmeraldComponent, PlayerTransform.transform.position, true);
```

{% endcode %}

## Clear Target To Follow

Clears the AI's Target to Follow transform so it will be no longer be following it. This will also stop the AI from being a Companion or Pet AI.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Detection.ClearTargetToFollow(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Detection.ClearTargetToFollow(EmeraldComponent);
```

{% endcode %}

## Check For Player Detection

Checks to see if the player is currently within the AI's detection radius by returning true or false (this can be true even if the player is an enemy).

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Detection.CheckForPlayerDetection(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Detection.CheckForPlayerDetection(EmeraldComponent);
```

{% endcode %}

## Set Ignored Target

Adds the specified ignored target to the static EmeraldDetection IgnoredTargetsList. This will not allow the target to be detected by any AI.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Detection.SetIgnoredTarget(Transform TargetTransform)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example
EmeraldAPI.Detection.SetIgnoredTarget(YourPlayerGameObject.transfrom);
```

{% endcode %}

## Clear Ignored Target

Removes the specified ignored target from the static EmeraldDetection IgnoredTargetsList.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Detection.ClearIgnoredTarget(Transform TargetTransform)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example
EmeraldAPI.Detection.ClearIgnoredTarget(YourPlayerGameObject.transfrom);
```

{% endcode %}

## Clear All Ignored Targets

Clears all ignored targets from the static EmeraldDetection IgnoredTargetsList.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Detection.ClearAllIgnoredTargets()
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example
EmeraldAPI.Detection.ClearAllIgnoredTargets();
```

{% endcode %}
