---
name: "nearestObject"
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/nearestObject
revid: 377544
updated: 2026-01-02T06:54:36Z
---

# nearestObject

*Command · Object Detection · Arma 3 v0.50 · introduced in Operation Flashpoint v1.00*

## Description

Returns the nearest object of given type (or inherited classes) to given position within a sphere. Hardcoded radius is 50 meters.
Unlike with [nearestObjects](../commands/nearestObjects.md), where distance is measured in 2D space, [nearestObject](../commands/nearestObject.md) will be closest object in 3D space.

> [!NOTE]
> - in Operation Flashpoint, only objects of the exact provided class are found.
> - if an object ID is used ([#Syntax 4](../commands/nearestObject.md#syntax-4), see [#Example 2](../commands/nearestObject.md#example-2)) the search range is unlimited

## Syntax

### Syntax 1

```sqf
nearestObject [position, type]
```

**Parameters:**

- `position`: [Object](../topics/Object.md) or [Position2D](../topics/Position.md#introduction) or [Position3D](../topics/Position.md#introduction) - position to start search at
- `type`: [String](../topics/String.md) - type of object (see [typeOf](../commands/typeOf.md), class type)

**Returns:** [Object](../topics/Object.md) - nearest object, [objNull](../commands/objNull.md) otherwise

### Syntax 2

```sqf
nearestObject position
```

**Parameters:**

- `position`: [Position2D](../topics/Position.md#introduction) or [Position3D](../topics/Position.md#introduction) - position to start search at

**Returns:** [Object](../topics/Object.md) - nearest object, [objNull](../commands/objNull.md) otherwise

### Syntax 3

```sqf
position nearestObject typeOrId
```

**Parameters:**

- `position`: [Position3D](../topics/Position.md#introduction) or [Position2D](../topics/Position.md#introduction) - position to start search at
- `typeOrId`: [String](../topics/String.md) - type of object (see [typeOf](../commands/typeOf.md), class type) or Arma 3 v2.10 Visitor id (see [getObjectID](../commands/getObjectID.md))

**Returns:** [Object](../topics/Object.md) - nearest object, [objNull](../commands/objNull.md) otherwise

### Syntax 4

```sqf
position nearestObject id
```

**Parameters:**

- `position`: [Position2D](../topics/Position.md#introduction) or [Position3D](../topics/Position.md#introduction) - position to start search at
- `id`: [Number](../topics/Number.md) - object Visitor id

**Returns:** [Object](../topics/Object.md) - nearest object, [objNull](../commands/objNull.md) otherwise

## Examples

### Example 1

```sqf
_nObject = nearestObject [2345, 6789];
_nObject = nearestObject [player, "StreetLamp"];
```

### Example 2

Return the object with ID 123456:

```sqf
_nObject = [0,0,0] nearestObject 123456;
```

### Example 3

```sqf
_nObject = getPos player nearestObject "StreetLamp";
```

### Example 4

Return the nearest object with ([typeOf](../commands/typeOf.md) _nObject == "#XXXX") -> #mark, #slop, etc. Unlimited search range:

```sqf
_nObject = _position nearestObject -1;
```

Return the nearest object with ([typeOf](../commands/typeOf.md) _nObject != ""). Search range is 50m:

```sqf
_nObject = nearestObject _position;
```

### Example 5

(See also [allMissionObjects](../commands/allMissionObjects.md)):

```sqf
_blood    = nearestObject [player, "#slop"];
_step    = nearestObject [player, "#mark"];
_track    = nearestObject [player, "#track"];
_crater    = nearestObject [player, "#crater"];
```

## See also

[nearestObjects](../commands/nearestObjects.md) · [nearObjectsReady](../commands/nearObjectsReady.md) · [nearObjects](../commands/nearObjects.md) · [objectFromNetId](../commands/objectFromNetId.md) · [nearEntities](../commands/nearEntities.md) · [entities](../commands/entities.md) · object · [nearestBuilding](../commands/nearestBuilding.md) · [nearestTerrainObjects](../commands/nearestTerrainObjects.md) · [nearestMines](../commands/nearestMines.md)

## Community notes

**Gnashes** — 2019-01-29

The ID for Syntax 4 may be dynamically obtained via the following (as of Arma 3 v1.88):
(for Arma 3 v2.10 or newer, use [getObjectID](../commands/getObjectID.md) instead)

```sqf
// returns Object Terrain/Visitor ID, or -1 if no ID found (invalid/null object)
cursorObject call {
    private _obj = str (param [0, objNull]);
    private _id = -1;

    private _find = ((_obj find "#") + 2);
    if (_find > 1) then
    {
        private _len = ((_obj find ":") - _find);
        _id = _obj select [_find, _len];
        parseNumber _id;
    };
    _id
};
```

---

**blackfisch** — 2020-02-12

Note, that if you want to check for the nearest Unit you have to check for `CAManBase` instead of `Man`, since `Man` will also return any wildlife population in that area:

```sqf
nearestObject [player, "Man"];            // could possibly return rabbits or other wildlife
nearestObject [player, "CAManBase"];    // only returns units
```

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