Skip to main content

Entities

Functions

countEntities

countEntities(entityType?, variant?, subType?, ignoreFriendly?): int

Helper function to count the number of entities in room. Use this over the vanilla Isaac.CountEntities method to avoid having to specify a spawner and to handle ignoring charmed enemies.

Parameters

NameTypeDefault valueDescription
entityType-1 | EntityType-1Optional. Default is -1, which matches every entity type.
variantnumber-1Optional. Default is -1, which matches every variant.
subTypenumber-1Optional. Default is -1, which matches every sub-type.
ignoreFriendlybooleanfalseOptional. Default is false. Will throw a runtime error if set to true and the entityType is equal to -1.

Returns

int

Defined in

packages/isaacscript-common/src/functions/entities.ts:47


doesAnyEntityExist

doesAnyEntityExist(entityTypes, ignoreFriendly?): boolean

Helper function to check if one or more matching entities exist in the current room. It uses the doesEntityExist helper function to determine this.

Parameters

NameTypeDefault valueDescription
entityTypesReadonlySet<EntityType> | readonly EntityType[]undefinedAn array or set of the entity types that you want to check for. Will return true if any of the provided entity types exist.
ignoreFriendlybooleanfalseOptional. Default is false.

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/entities.ts:90


doesEntityExist

doesEntityExist(entityType?, variant?, subType?, ignoreFriendly?): boolean

Helper function to check if one or more of a specific kind of entity is present in the current room. It uses the countEntities helper function to determine this.

Parameters

NameTypeDefault valueDescription
entityType-1 | EntityType-1Optional. Default is -1, which matches every entity type.
variantnumber-1Optional. Default is -1, which matches every variant.
subTypenumber-1Optional. Default is -1, which matches every sub-type.
ignoreFriendlybooleanfalseOptional. Default is false.

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/entities.ts:114


getClosestEntityTo

getClosestEntityTo<T>(referenceEntity, entities, filterFunc?): T | undefined

Given an array of entities, this helper function returns the closest one to a provided reference entity.

For example:

const player = Isaac.GetPlayer();
const gapers = getEntities(EntityType.GAPER);
const closestGaper = getClosestEntityTo(player, gapers);

Type parameters

NameType
Textends AnyEntity

Parameters

NameTypeDescription
referenceEntityEntityThe entity that is close by.
entitiesreadonly T[]The array of entities to look through.
filterFunc?(entity: T) => booleanOptional. A function to filter for a specific type of entity, like e.g. an enemy with a certain amount of HP left.

Returns

T | undefined

Defined in

packages/isaacscript-common/src/functions/entities.ts:141


getConstituentsFromEntityID

getConstituentsFromEntityID(entityID): [entityType: EntityType, variant: int, subType: int]

Helper function to get the entity type, variant, and sub-type from an EntityID.

Parameters

NameType
entityIDEntityID

Returns

[entityType: EntityType, variant: int, subType: int]

Defined in

packages/isaacscript-common/src/functions/entities.ts:164


getEntities

getEntities(entityType?, variant?, subType?, ignoreFriendly?): readonly Entity[]

Helper function to get all of the entities in the room or all of the entities that match a specific entity type / variant / sub-type.

Due to bugs with Isaac.FindInRadius, this function uses Isaac.GetRoomEntities, which is more expensive but also more robust. (If a matching entity type is provided, then Isaac.FindByType will be used instead.)

For example:

// Make all of the entities in the room invisible.
for (const entity of getEntities()) {
entity.Visible = false;
}

Parameters

NameTypeDefault valueDescription
entityType-1 | EntityType-1Optional. If specified, will only get the entities that match the type. Default is -1, which matches every type.
variantnumber-1Optional. If specified, will only get the entities that match the variant. Default is -1, which matches every variant.
subTypenumber-1Optional. If specified, will only get the entities that match the sub-type. Default is -1, which matches every sub-type.
ignoreFriendlybooleanfalseOptional. If set to true, it will exclude friendly NPCs from being returned. Default is false. Will only be taken into account if the entityType is specified.

Returns

readonly Entity[]

Defined in

packages/isaacscript-common/src/functions/entities.ts:237


getEntityFields

getEntityFields(entity): LuaMap<string, boolean | number | string>

Helper function to get all the fields on an entity. For example, this is useful for comparing it to another entity later. (One option is to use the logTableDifferences function for this.)

This function will only get fields that are equal to booleans, numbers, or strings, or Vectors, as comparing other types is non-trivial.

Parameters

NameType
entityEntity

Returns

LuaMap<string, boolean | number | string>

Defined in

packages/isaacscript-common/src/functions/entities.ts:257


getEntityFromPtrHash

getEntityFromPtrHash(ptrHash): Entity | undefined

Helper function to get an entity from a PtrHash. Note that doing this is very expensive, so you should only use this function when debugging. (Normally, if you need to work backwards from a reference, you would use an EntityPtr instead of a PtrHash.

Parameters

NameType
ptrHashPtrHash

Returns

Entity | undefined

Defined in

packages/isaacscript-common/src/functions/entities.ts:320


getEntityID

getEntityID(entity): EntityID

Helper function to get a string containing the entity's type, variant, and sub-type.

Parameters

NameType
entityEntity

Returns

EntityID

Defined in

packages/isaacscript-common/src/functions/entities.ts:326


getEntityIDFromConstituents

getEntityIDFromConstituents(entityType, variant, subType): EntityID

Helper function to get a formatted string in the format returned by the getEntityID function.

Parameters

NameType
entityTypeEntityType
variantint
subTypeint

Returns

EntityID

Defined in

packages/isaacscript-common/src/functions/entities.ts:333


getFilteredNewEntities

getFilteredNewEntities<T>(oldEntities, newEntities): readonly T[]

Helper function to compare two different arrays of entities. Returns the entities that are in the second array but not in the first array.

Type parameters

NameType
Textends AnyEntity

Parameters

NameType
oldEntitiesreadonly T[]
newEntitiesreadonly T[]

Returns

readonly T[]

Defined in

packages/isaacscript-common/src/functions/entities.ts:345


hasArmor

hasArmor(entity): boolean

Helper function to see if a particular entity has armor. In this context, armor refers to the damage scaling mechanic. For example, Ultra Greed has armor, but a Gaper does not.

For more on armor, see the wiki: https://bindingofisaacrebirth.fandom.com/wiki/Damage_Scaling

Parameters

NameType
entityEntity

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/entities.ts:367


isActiveEnemy

isActiveEnemy(entity): boolean

Helper function to detect if a particular entity is an active enemy. Use this over the Entity.IsActiveEnemy method since it is bugged with friendly enemies, Grimaces, Ultra Greed, and Mother.

Parameters

NameType
entityEntity

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/entities.ts:377


isEntityMoving

isEntityMoving(entity, threshold?): boolean

Helper function to measure an entity's velocity to see if it is moving.

Use this helper function over checking if the velocity length is equal to 0 because entities can look like they are completely immobile but yet still have a non zero velocity. Thus, using a threshold is needed.

Parameters

NameTypeDefault valueDescription
entityEntityundefinedThe entity whose velocity to measure.
thresholdnumber0.01Optional. The threshold from 0 to consider to be moving. Default is 0.01.

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/entities.ts:458


parseEntityID

parseEntityID(entityID): [entityType: EntityType, variant: int, subType: int] | undefined

Helper function to parse a string that contains an entity type, a variant, and a sub-type, separated by periods.

For example, passing "45.0.1" would return an array of [45, 0, 1].

Returns undefined if the string cannot be parsed.

Parameters

NameType
entityIDstring

Returns

[entityType: EntityType, variant: int, subType: int] | undefined

Defined in

packages/isaacscript-common/src/functions/entities.ts:470


parseEntityTypeVariantString

parseEntityTypeVariantString(entityTypeVariantString): [entityType: EntityType, variant: int] | undefined

Helper function to parse a string that contains an entity type and a variant separated by a period.

For example, passing "45.0" would return an array of [45, 0].

Returns undefined if the string cannot be parsed.

Parameters

NameType
entityTypeVariantStringstring

Returns

[entityType: EntityType, variant: int] | undefined

Defined in

packages/isaacscript-common/src/functions/entities.ts:511


removeAllMatchingEntities

removeAllMatchingEntities(entityType, entityVariant?, entitySubType?, cap?): readonly Entity[]

Helper function to remove all of the matching entities in the room.

Parameters

NameTypeDefault valueDescription
entityTypeEntityTypeundefinedThe entity type to match.
entityVariantnumber-1Optional. The variant to match. Default is -1, which matches every variant.
entitySubTypenumber-1Optional. The sub-type to match. Default is -1, which matches every sub-type.
capundefined | intundefinedOptional. If specified, will only remove the given amount of collectibles.

Returns

readonly Entity[]

An array of the entities that were removed.

Defined in

packages/isaacscript-common/src/functions/entities.ts:545


removeEntities

removeEntities<T>(entities, cap?): readonly T[]

Helper function to remove all of the entities in the supplied array.

Type parameters

NameType
Textends AnyEntity

Parameters

NameTypeDescription
entitiesreadonly T[]The array of entities to remove.
cap?intOptional. If specified, will only remove the given amount of entities.

Returns

readonly T[]

An array of the entities that were removed.

Defined in

packages/isaacscript-common/src/functions/entities.ts:562


rerollEnemy

rerollEnemy(entity): Entity | undefined

Helper function to reroll an enemy. Use this instead of the vanilla "Game.RerollEnemy" function if you want the rerolled enemy to be returned.

Parameters

NameTypeDescription
entityEntityThe entity to reroll.

Returns

Entity | undefined

If the game failed to reroll the enemy, returns undefined. Otherwise, returns the rerolled entity.

Defined in

packages/isaacscript-common/src/functions/entities.ts:591


setEntityDamageFlash

setEntityDamageFlash(entity): void

Helper function to make an entity flash red like it is taking damage. This is useful when you want to make it appear as if an entity is taking damage without actually dealing any damage to it.

Parameters

NameType
entityEntity

Returns

void

Defined in

packages/isaacscript-common/src/functions/entities.ts:614


setEntityOpacity

setEntityOpacity(entity, alpha): void

Helper function to keep an entity's color the same values as it already is but set the opacity to a specific value.

Parameters

NameTypeDescription
entityEntityThe entity to set.
alphafloatA value between 0 and 1 that represents the fade amount.

Returns

void

Defined in

packages/isaacscript-common/src/functions/entities.ts:625


setEntityRandomColor

setEntityRandomColor(entity): void

Parameters

NameType
entityEntity

Returns

void

Defined in

packages/isaacscript-common/src/functions/entities.ts:630


spawn

spawn(entityType, variant, subType, positionOrGridIndex, velocity?, spawner?, seedOrRNG?): Entity

Helper function to spawn an entity. Use this instead of the Isaac.Spawn method if you do not need to specify the velocity or spawner.

Also see the spawnWithSeed helper function.

Parameters

NameTypeDefault valueDescription
entityTypeEntityTypeundefinedThe EntityType of the entity to spawn.
variantintundefinedThe variant of the entity to spawn.
subTypeintundefinedThe sub-type of the entity to spawn.
positionOrGridIndexint | VectorundefinedThe position or grid index of the entity to spawn.
velocityVectorVectorZeroOptional. The velocity of the entity to spawn. Default is VectorZero.
spawnerundefined | EntityundefinedOptional. The entity that will be the SpawnerEntity. Default is undefined.
seedOrRNGundefined | RNG | SeedundefinedOptional. The seed or RNG object to use to generate the InitSeed of the entity. Default is undefined, which will make the entity spawn with a random seed using the Isaac.Spawn method.

Returns

Entity

Defined in

packages/isaacscript-common/src/functions/entities.ts:658


spawnEntityID

spawnEntityID(entityID, positionOrGridIndex, velocity?, spawner?, seedOrRNG?): Entity

Helper function to spawn the entity corresponding to an EntityID.

Parameters

NameTypeDefault valueDescription
entityIDEntityIDundefinedThe EntityID of the entity to spawn.
positionOrGridIndexint | VectorundefinedThe position or grid index of the entity to spawn.
velocityVectorVectorZeroOptional. The velocity of the entity to spawn. Default is VectorZero.
spawnerundefined | EntityundefinedOptional. The entity that will be the SpawnerEntity. Default is undefined.
seedOrRNGundefined | RNG | SeedundefinedOptional. The seed or RNG object to use to generate the InitSeed of the entity. Default is undefined, which will make the entity spawn with a random seed using the Isaac.Spawn method.

Returns

Entity

Defined in

packages/isaacscript-common/src/functions/entities.ts:715


spawnWithSeed

spawnWithSeed(entityType, variant, subType, positionOrGridIndex, seedOrRNG, velocity?, spawner?): Entity

Helper function to spawn an entity. Use this instead of the Game.Spawn method if you do not need to specify the velocity or spawner.

Parameters

NameTypeDefault value
entityTypeEntityTypeundefined
variantintundefined
subTypeintundefined
positionOrGridIndexint | Vectorundefined
seedOrRNGRNG | Seedundefined
velocityVectorVectorZero
spawnerundefined | Entityundefined

Returns

Entity

Defined in

packages/isaacscript-common/src/functions/entities.ts:738