Kill Objective

Overview

KillObjective tracks how many enemies of a specified type the player has killed. It listens to QuestEventType.EnemyKilled events published via the QuestEventBus and increments its kill count each time a matching event arrives.

It supports two targeting modes:

  • Tag-based — matches any enemy whose reported ID matches the targetTag field. Used for type-based objectives like "Kill 10 Orcs".

  • Specific enemy — when specificEnemyId is set, only that exact ID counts. Used for named enemy objectives like "Defeat the Orc Warlord".

KillObjective is added as an objective entry on a Quest ScriptableObject. It is not a component. The corresponding scene component that fires kill events is QuestEnemyReporterarrow-up-right.


Fields

Kill Objective Settings

Field
Type
Description

Target Tag

string

The enemy identifier to match against. Should match the Enemy ID reported by QuestEnemyReporter (which is typically the enemy's Unity tag or GameObject name). Default "Enemy".

Specific Enemy ID

string

When set, only enemies reporting this exact ID will count. Takes priority over Target Tag for both matching and progress tracking. Leave empty to use tag-based matching.

Required Kills

int

How many kills are needed to complete this objective. Default 1.


Inherited Fields (from QuestObjective)

Field
Type
Description

Objective ID

string

Auto-generated GUID uniquely identifying this objective within its quest.

Description

string

Text shown to the player in the Quest Journal and HUD tracker.

Is Optional

bool

When true, this objective does not need to be completed for the quest to complete.


How It Works

Matching

When an EnemyKilledEventData event arrives, QuestManager derives a tracking key from the event:

It then calls QuestProgress.AddKill(key) on all active quests. KillObjective.CheckCompletion then reads back the kill count using:

  • progress.GetKillCount(specificEnemyId) — if specificEnemyId is set

  • progress.GetKillCount(targetTag) — otherwise

For the most common setup — QuestEnemyReporter with Identification Type: Tag — the enemy's Unity tag is reported as enemyId, which means Target Tag on the objective should match the enemy's Unity tag exactly.

Completion Check

Event Subscription Lifecycle

When the parent quest starts, QuestManager calls SubscribeToEvents(eventBus), subscribing this objective to QuestEventType.EnemyKilled. When the quest ends (completed, failed, or abandoned), UnsubscribeFromEvents(eventBus) removes the subscription. Duplicate subscriptions are guarded against.


Connecting to the Scene

KillObjective requires QuestEnemyReporter components attached to enemy GameObjects in the scene. The value reported by QuestEnemyReporter as its Enemy ID must exactly match the targetTag or specificEnemyId field on the objective.

Quest ScriptableObject
Enemy GameObject

targetTag = "Orc"

QuestEnemyReporter with Enemy ID = "Orc" (tag-based)

specificEnemyId = "OrcWarlord"

QuestEnemyReporter with Enemy ID = "OrcWarlord" (custom)

QuestEnemyReporter can report multiple IDs per kill using its Additional IDs list, allowing one enemy death to count toward multiple KillObjective entries simultaneously (e.g. an "OrcWarlord" that also counts toward a generic "Orc" objective).


Example Configurations

"Kill 10 Orcs" — tag-based

Scene setup: enemy GameObjects tagged "Orc" with QuestEnemyReporter using Identification Type: Tag.


"Defeat the Orc Warlord" — specific named enemy

Scene setup: boss GameObject with QuestEnemyReporter set to Identification Type: Custom, Enemy ID = "OrcWarlord".


"Slay 5 undead" — category covering multiple enemy types

Scene setup: multiple enemy types (skeletons, zombies, wraiths) all tagged "Undead". Each has a QuestEnemyReporter using Identification Type: Tag. Optionally, enemies with a different primary tag can include "Undead" in their QuestEnemyReporter Additional IDs list.


Other Notes

  • targetTag and specificEnemyId matching is exact and case-sensitive. "Orc" and "orc" are treated as different enemies.

  • When specificEnemyId is set, targetTag is completely ignored for both matching and progress tracking. Only one mode is active at a time.

  • Kill counts are cumulative per quest session. There is no built-in way to decrement the count — if a respawning enemy should only count once, set QuestEnemyReporter.UnlimitedDeaths to false (the default), which prevents the same enemy instance from reporting more than once.

  • If two active quests both have a KillObjective matching the same enemy ID, a single kill advances the counter in both simultaneously.

  • The field is named targetTag for historical reasons, but it is compared against enemyData.enemyId (the primary reported ID from QuestEnemyReporter) — not enemyData.enemyTag (the category tag). In most setups these are the same string, but be aware of the distinction if your QuestEnemyReporter reports different values for each.

Last updated