π Use / World¶
Simple 2D trigger-based pickup behaviours for demos and prototypes.
These show how to add items to inventory or trigger use-effects directly from world objects.
π§© Purpose¶
Provide minimal, ready-to-use pickup components for 2D scenes, demonstrating:
- inventory grants
- optional effect triggers
- optional combined behaviour (Pickups integration)
These scripts are intentionally lightweight, readable, and easy to modify for your own game logic.
π¦ Components¶
| Script | Description |
|---|---|
ItemPickup2D |
Adds an ItemDefinition to the colliding GameObjectβs inventory, then destroys itself. |
WorldItemToInventory2D |
Near-identical variant of ItemPickup2D (kept for legacy/demo separation). |
UnifiedPickup2D |
With or without REV_PICKUPS_PRESENT, can run an effect, give items, or both. |
π Quickstart¶
- Create a pickup prefab or empty GameObject.
- Add
ItemPickup2DorUnifiedPickup2D. - Assign:
- ItemDefinition
- Quantity
- (Optional) effect (for
UnifiedPickup2D) - Add a 2D Collider and set
isTrigger = true. - Ensure the colliding GameObject itself has a
CharacterInventory(and thus anInventoryOwnerHook). - Ensure a
SceneInventoryServiceandItemDatabaseexist in the scene.
When the owner enters the trigger:
- Item is added (inventory modes)
- Effect is executed (effect modes)
- Pickup object is destroyed (when
destroyOnTrigger == true)
βοΈ Behaviour Details¶
ItemPickup2D¶
The simplest case:
svc.GiveExact(other.gameObject, stack, container);
Destroy(gameObject);
- Works only if the colliding GameObject itself owns the inventory
- Uses implicit conversion from
stringβContainerId - Quantity is clamped by container rules (
maxStack)
WorldItemToInventory2D¶
- Behaviour is effectively identical to
ItemPickup2D - Exists for legacy/demo clarity or alternate naming conventions
- No delayed, manual, or queued behaviour
UnifiedPickup2D¶
Mode-dependent behaviour:
- EffectOnly
-
Runs the configured effect (native or Pickups-based)
-
InventoryOnly
-
Adds the item to inventory
-
Both
- Runs the effect first, then adds the item
Finally:
if (destroyOnTrigger)
Destroy(gameObject);
Effect-first execution matters when effects modify or destroy the target.
Dependency Notes¶
- If
REV_PICKUPS_PRESENTis not defined: - Effect paths compile out
-
Inventory path still works
-
If
REV_PICKUPS_PRESENTis defined: PickupEffectassets and decorated chains are supported-
Context-aware effects are routed through adapters
-
OnValidateensures: - Container name is trimmed
- Quantity is clamped to β₯ 1
- A warning is logged if the collider is not a trigger
β οΈ Gotchas¶
-
Inventory owner must be the collider itself
No parent/child lookup is performed β attachCharacterInventoryto the same GameObject as the collider. -
Requires
SceneInventoryService+ItemDatabase
Without them, pickups safely do nothing. -
2D only
For 3D games, replaceCollider2D/OnTriggerEnter2Dwith 3D equivalents. -
Example code, not production systems
Extend with animations, VFX, pooling, rarity shine, audio, etc. as needed.