Collect Objective
Overview
CollectObjective tracks how many of a specific item the player has collected. It listens to QuestEventType.ItemCollected events published via the QuestEventBus and advances its count each time an event reports a matching item ID.
CollectObjective is added as an objective entry on a Quest ScriptableObject. It is not a component — it is a serialized data class. The corresponding scene component that fires collection events is QuestCollectable.
Fields
Collect Objective Settings
Item ID
string
The item identifier this objective listens for. Must exactly match the itemId configured on the corresponding QuestCollectable component(s) in the scene. Case-sensitive.
Required Amount
int
The total quantity that must be collected 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 describing what to collect. Displayed 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 ItemCollectedEventData event arrives, QuestManager checks whether eventData.itemId matches any active CollectObjective.itemId. When a match is found, QuestProgress.AddItem(itemId, quantity) is called, incrementing the stored count by the quantity reported in the event.
QuestCollectable reports a quantity value (default 1) alongside the item ID, meaning a single collection event can advance the counter by more than one if a pickup represents multiple items.
Completion Check
The stored item count is compared against requiredAmount each time CheckQuestProgress runs in QuestManager, which is after every ItemCollected event is processed.
Event Subscription Lifecycle
When the parent quest starts, QuestManager calls SubscribeToEvents(eventBus) on this objective, subscribing it to QuestEventType.ItemCollected. When the quest ends (completed, failed, or abandoned), UnsubscribeFromEvents(eventBus) is called. Duplicate subscriptions are guarded against — subscribing twice has no effect.
Connecting to the Scene
CollectObjective requires one or more QuestCollectable components placed on collectible objects in the scene. The itemId on the objective and the resolved itemId on every QuestCollectable that should count toward this objective must be identical strings.
CollectObjective.itemId = "IronOre"
QuestCollectable.itemId = "IronOre"
CollectObjective.requiredAmount = 5
QuestCollectable.quantity = 1 (×5 separate pickups)
CollectObjective.requiredAmount = 5
QuestCollectable.quantity = 5 (single pickup worth 5)
Multiple QuestCollectable objects with the same itemId all contribute to the same objective counter — place as many as your scene requires.
Example Configurations
"Collect 5 iron ore"
"Pick up the ancient key" — single item
"Gather 10 herbs" — using quantity > 1 per pickup
Scene setup: each QuestCollectable has quantity = 2, so 5 pickups complete the objective.
Other Notes
itemIdmatching is exact and case-sensitive."IronOre"and"ironore"are treated as different items.Item counts are cumulative across the entire quest session. There is no built-in decrement if the player drops or loses items — if your game requires that behaviour, it would need to be implemented in a custom objective type or via direct
QuestProgressmanipulation.Collection is tracked independently per quest. If two active quests both have a
CollectObjectivewith the sameitemId, collecting one item advances the counter in both simultaneously.If
QuestCollectable.reportOnlyOnceis enabled (the default), each individual pickup object can only contribute once — respawn the object or useResetCollectedState()if it needs to be collectible again.
Last updated