Quest Collectable

QuestCollectable.cs

Overview

QuestCollectable is a bridge component that connects physical world items to the Quest Forge collection tracking system. When an item is collected — via interaction, physical pickup, trigger zone, or manual call — this component reports the event to QuestEventReporter, which updates any active CollectObjective objectives.

Add this component alongside your existing item pickup logic. It does not replace MInteract or Pickable; it listens to their events and translates them into quest system signals.

Inspector Properties

Collection Mode

Property
Description

Collection Mode

Defines how this item is collected. See Collection Modes below.

Item Identification

Property
Description

Identification Type

How the Item ID is determined. See Identification Types below.

Item ID

The string identifier sent to the quest system. Must exactly match the itemId defined in the corresponding CollectObjective.

Item ID From Int

Optional IntReference used to derive the item ID (for inventory system integration). Used with IntVarReference identification type.

Auto Detect ID

When enabled, the Item ID is derived automatically at runtime using the chosen Identification Type.

Collection Settings

Property
Description

Quantity

How many items this single pickup represents. Defaults to 1.

Report Only Once

Prevents this component from reporting more than once. Recommended for non-respawning items.

Report Delay

Seconds to wait before reporting to the quest system. Useful to sync with animations or effects.

Trigger Settings (TriggerCollision mode only)

Property
Description

Collector Tag

The Unity tag of the GameObject that can collect this item (default: Player).

Destroy On Collect

Destroys the GameObject after collection in TriggerCollision mode.

Destroy Delay

Seconds to wait before destroying, allowing effects to complete.

Malbers Integration

Property
Description

MInteract

Reference to the MInteract component. Auto-detected if not assigned.

Pickable

Reference to the Pickable component. Auto-detected if not assigned.

Auto Subscribe

Automatically subscribes to MInteract.OnInteractWithGO or Pickable.OnPicked events on Start.

Quest Requirements

Property
Description

Require Active Quest

When enabled, collection is only permitted if the specified quest is currently active.

Required Quest

The Quest ScriptableObject that must be active for collection to be allowed.

Blocked Message

A message logged to the console when collection is blocked. Can be extended to drive UI prompts.

Events

Event
Type
Description

On Collected

UnityEvent<GameObject>

Fired when the item is successfully collected. Passes the collecting GameObject.

On Collection Blocked

UnityEvent

Fired when collection is attempted but blocked due to quest requirements not being met.

On Pre Report

UnityEvent

Fired just before the collection is reported to the quest system.

Visual Feedback

Property
Description

Collect Effect

A ParticleSystem played on collection.

Collect Sound

An AudioClip played on collection.

Audio Source

The AudioSource used for playback. Auto-created if a collect sound is assigned but no source exists.


Collection Modes

Mode
Description

MInteract

Listens to the OnInteractWithGO event from a MInteract component on the same GameObject. The player must interact using the Malbers interaction system.

Pickable

Listens to the OnPicked event from a Pickable component on the same GameObject. The item is collected when physically picked up.

TriggerCollision

Uses OnTriggerEnter / OnTriggerEnter2D. The item is collected when the player walks into the collider zone. Requires a Collider with Is Trigger enabled.

Manual

Does not subscribe to any automatic events. Call Collect() from your own scripts or Unity Events.


Identification Types

Type
Description

Custom

Uses the string value entered in the Item ID field directly.

GameObjectName

Derives the ID from the GameObject's name, stripping (Clone) suffixes and trailing numbers (e.g. Potion 1Potion).

GameObjectTag

Uses the GameObject's Unity tag as the ID. Falls back to the Custom ID if the tag is Untagged.

IntVarReference

Uses the integer value from an IntReference ScriptableObject, converted to string. Falls back to Custom ID if no reference is assigned.


Public API

Method
Description

Collect(GameObject collector)

Collects the item and reports to the quest system. Pass the collecting GameObject for event data.

Collect()

Collects the item without specifying a collector. Suitable for Unity Events.

ForceCollect(GameObject collector)

Resets the collected state and collects again, even if already collected.

ResetCollectedState()

Resets the HasBeenCollected flag, allowing the item to be collected again (for respawning).

SetItemId(string newId)

Changes the Item ID at runtime.

SetQuantity(int newQuantity)

Changes the quantity value reported to the quest system at runtime.


Properties (Read-Only)

Property
Description

ItemId

The resolved Item ID used at runtime.

Quantity

The quantity this pickup represents.

HasBeenCollected

Whether this item has already been collected.

CanCollect

Whether collection is currently permitted (not yet collected, and quest requirements met).

Mode

The current CollectionMode setting.


How Reporting Works

When collection is confirmed, QuestCollectable calls:

This sends the Item ID and quantity to the QuestEventReporter, which broadcasts the event to all active quest instances. Any CollectObjective whose itemId matches the reported ID will increment its collected count by the specified quantity.

The full flow is:

  1. Collection is triggered (via MInteract, Pickable, trigger collision, or manual Collect() call)

  2. CanCollect is evaluated — checks hasBeenCollected and any active quest requirement

  3. If blocked, OnCollectionBlocked fires and the blocked message is logged

  4. If permitted and Report Only Once is enabled, hasBeenCollected is set to true

  5. Collection effects play (particle system, audio)

  6. OnPreReport fires

  7. After any configured delay, QuestEventReporter.Instance.ReportItemCollected(itemId, quantity) is called

  8. OnCollected fires, passing the collecting GameObject

  9. If mode is TriggerCollision and Destroy On Collect is enabled, the GameObject is destroyed after the configured delay

Other Notes

  • The Item ID set here must exactly match the itemId field on the corresponding CollectObjective in your Quest ScriptableObject. Case-sensitive.

  • This component relies on QuestEventReporter.Instance. If no QuestEventReporter is present in the scene (as part of QuestForgeManagers), collection events will not be reported and a warning will be logged.

  • Destruction of the item after collection in TriggerCollision mode is handled by this component. In MInteract and Pickable modes, the items are typically managed by those systems — destroyOnCollect is not applied to those modes.

Last updated