# AIGetClosestUnit
Flags —
Native
# Arguments
unit
— uunitgroup
— groupbool
— needsPath
Returns — unit
native unit AIGetClosestUnit(
unit u,
unitgroup group,
bool needsPath,
);
# Related
Category: Unclassified
# Examples
mods/core.sc2mod — base.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1198
// if we're idle, head toward closest town center
dropOffs = AIGetBuildingGroup(player, c_buildingTypeTownHall);
bestDropOff = AIGetClosestUnit(aiUnit, dropOffs, true);
if (bestDropOff != c_nullUnit) {
// move to it's position
mods/starcoop/starcoop.sc2mod — base.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:1393
// if we're idle, head toward closest town center
dropOffs = AIGetBuildingGroup(player, c_buildingTypeTownHall);
bestDropOff = AIGetClosestUnit(aiUnit, dropOffs, true);
if (bestDropOff != c_nullUnit) {
// move to it's position