ItemDatabase

Singleton ScriptableObject that serves as the central registry of all IItemFactory assets. Provides static lookup of item factories by ID for spawning items at runtime.

Definition

Namespace: Paragon.Townskeep.ItemSystem Assembly: Townskeep.dll

[SingletonSettings(AssetPath = "Item/Item Database")]
public class ItemDatabase : ScriptableFactoryDatabase<ItemDatabase, IItemFactory<Item, ItemData>>

Inheritance: SingletonScriptableObject<ItemDatabase> → ScriptableFactoryDatabase<ItemDatabase, IItemFactory<Item, ItemData>> → ItemDatabase

Remarks

ItemDatabase is a thin specialization of the generic ScriptableFactoryDatabase from the Scriptable Factory system. It automatically discovers all IItemFactory<Item, ItemData> assets via the ScriptableFactoryRegistry on OnEnable() and indexes them in a dictionary keyed by each factory's hash code (which equals ItemData.ItemID).

The asset is located at Resources/Item/Item Database (configured via [SingletonSettings]).

circle-info

Factory hash codes are set to ItemData.ItemID by the ItemFactory override of GetHashCode(). This means ItemDatabase.GetFactory(itemId) looks up by the item's type ID.

Quick Lookup

Goal
How

Get a factory by ID

ItemDatabase.GetFactory(itemId)

Spawn an item by ID

ItemDatabase.GetFactory(itemId).NetworkSpawn(variantId)

Asset location

Resources/Item/Item Database

Methods (inherited)

GetFactory (static)

Returns the item factory registered with the given ID.

Parameter
Type
Description

index

int

The item type ID (matches ItemData.ItemID / factory hash code)

Returns: The IItemFactory<Item, ItemData> instance for the given ID.

circle-exclamation

OnEnable (inherited, virtual)

Called by Unity when the ScriptableObject is loaded. Populates the internal factory dictionary from ScriptableFactoryRegistry.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Spawning an Item by ID

Using ItemSpawner (higher-level API)

See Also

  • IItemFactory — interface for registered factories

  • ItemFactory — abstract factory implementation

  • ItemID — composite identifier used for lookups

  • ItemData — data record defining item properties

Last updated