Unit

class library.Unit

An instance of the class Unit represents one unit in the game. The units are not limited to moveable units, but every entity which is not part of the background is a unit. For example, the minerals and geysers are units as well as all buildings.

For all possible types of units see the enum library.UNIT_TYPEID. Some types of objects are almost the same, for example there are many types of mineral deposits, but all of them are mineable. This is one of the motivations behind the library.UnitType which aims to to make the list of types more manageable. The UnitType can be accessed by the Unit.unit_type property.

It is possible to use Unit as keys in a dictionary, which might be helpful for bookkeeping.

Properties:

Unit.buffs

Returns a list of BuffID

Unit.build_percentage
Unit.energy
Unit.facing

Returns the direction the unit is facing

Unit.hit_points
Unit.max_shields
Unit.max_energy
Unit.id
Unit.is_alive
Unit.is_blip

Returns true if unit is a “blip” - a ping on the map

Unit.is_being_constructed

Returns build_progress > 0

Unit.is_burrowed
Unit.is_cloaked
Unit.is_completed

Returns build_progress >= 1

Unit.is_flying
Unit.is_idle
Unit.is_powered
Unit.is_training
Unit.is_valid
Unit.player

Returns the constant corresponding to player which this unit belongs to. See Player constants for more information

Unit.position

The library.Point2D of the unit

Unit.current_ability_id

The AbilityID of currently used ability

Unit.progress

Returns the progress of currently used ability (-1 if not using ability)

Unit.radius

Retruns the radius of the unit

Unit.shields
Unit.tile_position

The library.Point2DI of the unit

Unit.unit_type

The library.UnitType of the unit

Unit.weapon_cooldown
Unit.is_carrying_minerals

Returns if this unit is currently holding minerals

Unit.is_carrying_gas

Returns if this unit is currently holding gas

Unit.target

Returns target if unit has one, otherwise will fail the assertion (make sure not to call this unless certain that the unit has a target!)

Unit.gas_left_in_refinery

This is used on the geyser. Returns the amount of gas left in refinery

Unit.minerals_left_in_mineralfield

Returns the amount of minerals left in mineralfield

Unit.owner

Returns the Player ID, the owner of the unit

Methods:

Unit.ability(*args, **kwargs)

Overloaded function.

  1. ability(self: library.Unit, arg0: sc2::SC2Type<sc2::ABILITY_ID>) -> None
  2. ability(self: library.Unit, arg0: sc2::SC2Type<sc2::ABILITY_ID>, arg1: sc2::Point2D) -> None
  3. ability(self: library.Unit, arg0: sc2::SC2Type<sc2::ABILITY_ID>, arg1: library.Unit) -> None

Call an ability directly, different abilities has different targets. Some target the unit itself (no argument), target a point (Point2D as argument) and some target a Unit (instance of Unit as argument)

Unit.is_constructing(self, unit_type: library.UnitType)

Returns true if the unit is currently constructing another unit of type unit_type. Note that unit_type needs to be an instance of library.UnitType

Unit.stop(self: library.Unit) → None
Unit.attack_unit(self: library.Unit, arg0: library.Unit) → None
Unit.attack_move(self: library.Unit, arg0: sc2::Point2D) → None
Unit.move(self, point)

Move the unit to the given point, the point being an instance of either library.Point2D or library.Point2DI.

Unit.right_click(self: library.Unit, arg0: library.Unit) → None

Same as right-clicking in the game, for example making workers mine minerals

Unit.repair(self: library.Unit, arg0: library.Unit) → None
Unit.build(self: library.Unit, building_type: UnitType, position: sc2::Point2DI) → None

Build unit of type building_type at given position

Unit.build_target(self: library.Unit, building_type: UnitType, target: library.Unit) → None

Build building_type on top of target Unit, useful for building refineries

Unit.train(self: library.Unit, unit_type: UnitType) → None

Train unit of type

Unit.research(self: library.Unit, upgrade_id: sc2::SC2Type<sc2::UPGRADE_ID>) → None

Research the given library.UPGRADE_ID

Unit.morph(self: library.Unit, unit_type: UnitType) → None

Morph into type of unit_type

Unit.has_target()

Returns True if the target has a valid target and False otherwise

Unit.hold_position(self: library.Unit) → None
Unit.stop_dance(self: library.Unit) → None

Stop and dance