Docs Menu
class: SpecterLocator
The base locator class. Locators are lazy-evaluated pipelines that do not execute until you await an action or assertion. Specter provides powerful filtering options to narrow down your queries in the hierarchy.
Strictness
Locators are strict. This means that all operations on locators that imply some target element will throw an exception if more than one element matches. For example, the following call throws if there are several buttons in the world:
await world.widget('Button').hardwareFocus();locator.filter
Narrows existing locator matches by filtering on specific properties or text.
Usage
const activeEnemies = world.actorByTag('Enemy').filter({ hasProperty: { 'IsAlive': true } });Arguments
optionsObjectFilter options containing hasProperty or hasText.
Returns
locator.and
Creates a locator that matches elements that satisfy both the original locator and the provided locator.
Usage
const healthPotionSlot = world.widget('InventorySlot').and(world.widgetByText('Health Potion'));Arguments
locatorSpecterLocatorThe locator to intersect with.
Returns
locator.or
Creates a locator that matches elements that satisfy either the original locator or the provided locator.
Usage
const anyMinion = world.actor('BP_Minion_Melee').or(world.actor('BP_Minion_Range'));Arguments
locatorSpecterLocatorThe locator to union with.
Returns
locator.all
Returns an array of locator pipelines pointing to their respective matches. This is useful when you need to iterate over multiple matched actors or widgets.
Usage
const minions = await world.actor('BP_Minion').all();
for (const minion of minions) {
await expect(minion).toBeVisible();
}Returns
- Promise<SpecterLocator[]>
locator.first
Returns a locator that resolves to the first matching element in the queried set.
Usage
const firstMinion = world.actor('BP_Minion').first();Returns
locator.last
Returns a locator that resolves to the last matching element in the queried set.
Usage
const lastMinion = world.actor('BP_Minion').last();Returns
locator.nth
Returns a locator that resolves to the n-th matching element in the queried set. It's zero based, nth(0) selects the first element.
Usage
const thirdMinion = world.actor('BP_Minion').nth(2);Arguments
indexnumberThe zero-based index of the element to select.
Returns
locator.count
Returns the number of elements matching the locator pipeline in the engine.
Usage
const numMinions = await world.actor('BP_Minion').count();
console.log(numMinions);Returns
- Promise<number>
Engine Bindings & Execution
Low-level methods for directly binding to C++ delegates, retrieving property values, and executing UFunctions.
locator.waitForEvent
Natively waits for a C++ UObject delegate or Blueprint Multicast delegate to broadcast on this specific target. Supports domain-specific autocomplete, predicate filtering, and payload typing.
Usage
// Resolve only when damage is greater than 50
await bossActor.waitForEvent('OnTakeAnyDamage', (data) => data.damage > 50);
// You can add full IntelliSense for custom events via module augmentation!
// In your test or setup file:
declare module '@specter-automation/test' {
interface CustomActorEvents {
OnShieldBroken: { currentShield: number; maxShield: number };
}
}
const shieldInfo = await playerActor.waitForEvent('OnShieldBroken');
console.log(shieldInfo.maxShield); // Fully typed numberArguments
eventNamestringThe name of the delegate to bind to.optionsOrPredicateFunction | Object(optional)A predicate function (payload) => boolean, or an options object { timeout, predicate }.
Returns
- Promise<any>
locator.waitForExist
Polls the engine until the locator resolves to at least 1 object. Bypasses Strict Mode during the wait.
Usage
await world.widget('VictoryScreen').waitForExist();Arguments
timeoutnumber(optional)Timeout in milliseconds (Default: 5000).
Returns
- Promise<void>
locator.client
Clones the locator and binds it to a different player/client's world connection, allowing you to query objects on a specific client's machine.
Usage
const player2Boss = bossLocator.client(world2);
await expect(player2Boss).toBeVisible();Arguments
worldSpecterWorldThe target client's world fixture.
Returns
- this
locator.callFunction
The Generic Bridge: Calls any C++ UFunction or Blueprint Callable function on the target object. Automatically handles serialization and parsing of structs, objects, and return values.
Note: If you have generated Strongly-Typed Blueprints, the functionName, args, and return type will be strictly typed and provide VS Code autocomplete.
Note: If you have generated Strongly-Typed Blueprints, the functionName, args, and return type will be strictly typed and provide VS Code autocomplete.
Usage
// 1. Get a returned struct
const location = await player.callFunction("K2_GetActorLocation");
// 2. Pass in structs and parameters
await player.callFunction("K2_SetActorLocation", {
NewLocation: { X: 0, Y: 0, Z: 1000 },
bSweep: false,
bTeleport: true,
SweepHitResult: {}
});
// 3. Read an object reference and chain a new locator
const weaponName = await player.callFunction("GetEquippedWeapon");
const weapon = world.actor(weaponName);
await weapon.callFunction("Fire");Arguments
functionNamestringThe exact name of the Unreal Engine function.argsobject(optional)A key-value map of parameters to pass.
Returns
- Promise<any>
locator.getPropertyValue
Directly reads the value of a UPROPERTY on the target object.
Usage
const health = await player.getPropertyValue("CurrentHealth");Arguments
propertyNamestringThe name of the UPROPERTY.
Returns
- Promise<any>
locator.trackProperty
Registers a UPROPERTY on this target for real-time engine telemetry event emission. Once tracked, the C++ USpecterSubsystem will immediately push an event whenever this variable changes, which can be awaited via world.waitForVariable().
Usage
const gameState = world.actor('GameStateBase');
const matchStateVar = await gameState.trackProperty('MatchState');
// Now wait for the transition event using the returned stable variable name:
await world.waitForVariable(matchStateVar, 'InProgress');Arguments
propertyNamestringThe name of the Blueprint or C++ UPROPERTY to monitor (e.g. 'MatchState', 'CurrentWave', 'bIsGameOver').
Returns
- Promise<string>
locator.trackAttribute
Registers a Gameplay Ability System (GAS) attribute on this actor's AbilitySystemComponent for push-based telemetry events.
Usage
const player = world.actor('BP_PlayerCharacter');
const healthVar = await player.trackAttribute('AttributeSet_Player', 'Health');
// Wait for health to drop below or transition to 0:
await world.waitForVariable(healthVar, '0');Arguments
attributeSetstringThe Attribute Set class name (e.g. 'HealthSet' or 'AttributeSet_Player').attributeNamestringThe attribute name (e.g. 'Health', 'Mana', 'Shield').
Returns
- Promise<string>
Materials & Visuals
Direct inspection getters for Materials on both Actors and UMG Widgets. Evaluates instantly.
locator.getMaterialScalarParameter
Reads the current float value of a scalar parameter on the assigned material.
Usage
const opacity = await ui.locator('FadeOverlay').getMaterialScalarParameter('Opacity');Arguments
parameterNamestringThe parameter name.optionsObject(optional)slotIndexnumber(optional)Defaults to0componentNamestring(optional)
Returns
- Promise<number>
locator.getMaterialVectorParameter
Reads the current color/vector value of a material parameter.
Usage
const color = await shield.getMaterialVectorParameter('GlowColor');
console.log(color.hex);Arguments
parameterNamestringThe parameter name.optionsObject(optional)slotIndexnumber(optional)Defaults to0componentNamestring(optional)
Returns
- Promise<{ r: number, g: number, b: number, a: number, hex: string }>
locator.getMaterialTextureParameter
Returns the name of the UTexture asset assigned to a material texture parameter.
Usage
const tex = await portrait.getMaterialTextureParameter('Icon');Arguments
parameterNamestringThe parameter name.optionsObject(optional)slotIndexnumber(optional)Defaults to0componentNamestring(optional)
Returns
- Promise<string>
locator.getMaterialName
Returns the name of the assigned Material or Material Instance asset at the given slot.
Usage
const matName = await terrain.getMaterialName();Arguments
optionsObject(optional)slotIndexnumber(optional)Defaults to0componentNamestring(optional)
Returns
- Promise<string>
locator.isDynamicMaterial
Checks if the material at the specified slot is a UMaterialInstanceDynamic (MID).
Usage
const isDynamic = await healthBar.isDynamicMaterial();Arguments
optionsObject(optional)slotIndexnumber(optional)Defaults to0componentNamestring(optional)
Returns
- Promise<boolean>