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
targetTagfield. Used for type-based objectives like "Kill 10 Orcs".Specific enemy — when
specificEnemyIdis 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 QuestEnemyReporter.
Fields
Kill Objective Settings
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)
QuestObjective)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)— ifspecificEnemyIdis setprogress.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.
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
targetTagandspecificEnemyIdmatching is exact and case-sensitive."Orc"and"orc"are treated as different enemies.When
specificEnemyIdis set,targetTagis 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.UnlimitedDeathstofalse(the default), which prevents the same enemy instance from reporting more than once.If two active quests both have a
KillObjectivematching the same enemy ID, a single kill advances the counter in both simultaneously.The field is named
targetTagfor historical reasons, but it is compared againstenemyData.enemyId(the primary reported ID fromQuestEnemyReporter) — notenemyData.enemyTag(the category tag). In most setups these are the same string, but be aware of the distinction if yourQuestEnemyReporterreports different values for each.
Last updated