---
name: "findNearestEnemy"
type: command
status: ok
groups: ["Object Detection"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/findNearestEnemy
revid: 377414
updated: 2026-01-02T06:45:18Z
---

# findNearestEnemy

*Command · Object Detection · Arma 3 v0.50 · introduced in Armed Assault v1.00*

## Description

Finds the nearest enemy to the specified position. Returns a null object if the object's group does not [know about](../commands/knowsAbout.md) any enemies. This command will return nearest object that is known to the unit and is considered enemy. An empty vehicle that is part of enemy group assets (see [addVehicle](../commands/addVehicle.md)) can be returned as valid nearest target.

## Syntax

```sqf
object findNearestEnemy position
```

**Parameters:**

- `object`: [Object](../topics/Object.md)
- `position`: [Object](../topics/Object.md) or [PositionAGL](../topics/Position.md#positionagl) or [Position2D](../topics/Position.md#introduction)

**Returns:** [Object](../topics/Object.md)

## Examples

### Example 1

```sqf
_myNearestEnemy = (units _myGroup select 0) findNearestEnemy player;
```

### Example 2

```sqf
_myNearestEnemy = player findNearestEnemy player;
```

## See also

[targets](../commands/targets.md) · [targetsQuery](../commands/targetsQuery.md) · [nearTargets](../commands/nearTargets.md) · [targetsAggregate](../commands/targetsAggregate.md) · [targetKnowledge](../commands/targetKnowledge.md) · [knowsAbout](../commands/knowsAbout.md) · [reveal](../commands/reveal.md) · [forgetTarget](../commands/forgetTarget.md) · [setTargetAge](../commands/setTargetAge.md) · [getHideFrom](../commands/getHideFrom.md) · [nearestBuilding](../commands/nearestBuilding.md) · [nearestObject](../commands/nearestObject.md) · [nearestObjects](../commands/nearestObjects.md) · [nearObjects](../commands/nearObjects.md) · [nearestLocation](../commands/nearestLocation.md) · [nearEntities](../commands/nearEntities.md) · [nearSupplies](../commands/nearSupplies.md) · [nearestLocationWithDubbing](../commands/nearestLocationWithDubbing.md) · [nearObjectsReady](../commands/nearObjectsReady.md) · [nearRoads](../commands/nearRoads.md) · [nearestMines](../commands/nearestMines.md)

<sub>Source: [BI Community Wiki — findNearestEnemy](https://community.bistudio.com/wiki/findNearestEnemy) (revision 377414).</sub>
