# AIGetClosestUnit

FlagsNative

# Arguments

  • unit — u
  • unitgroup — group
  • bool — needsPath

Returns — unit

native unit AIGetClosestUnit(
	unit u,
	unitgroup group,
	bool needsPath,
);

Category: Unclassified

# Examples

mods/core.sc2modbase.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.sc2modbase.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