Picking up and storing Item instances (NOT prefabs)

halgorithm

New member
I'm making a (third-person adventure camera only) game where each instance of an item in the world has runtime state that needs to persist seamlessly across picking up and dropping that instance. To give an example, a burning wooden spear might be launched at the player, who catches it in midair (auto-equipping it), dunks it in water to put out the fire, and finally throws this now-wet spear back at their opponent. They can also store a limited number of items in their backpack to equip at a later point, preserving any physical state the item had when it was stored in the backpack.

UCC provides an ItemPickup script for the simple case of adding a given quantity of an ItemType to the player's inventory, but it doesn't seem like this will work for me since ItemTypes are not instances of items but rather representations of a particular Item that gets added to your inventory. I need my inventory to contain actual item instances, multiple of which may belong to the same ItemType but each of which have their own state. I'm expecting I might have to do a bit of custom scripting to achieve this, but I would appreciate some guidance on where to start if I need to make modifications to the existing inventory system (or if already can support my use case, how I can add items to it in the way I need).

Any sort of guidance would be greatly appreciated! Thanks!
 
Last edited:
In this case I would create a script that is similar to the item pickup script with the addition of modifying the item's properties after the item has been picked up. This will give you the complete flexibility of using item types while also being able to modify the particular instance of that item.
 
Looking at the source for Inventory.cs, it seems that it's structured to only allow you to have one Item per ItemType at any time:

Code:
private Dictionary<ItemType, Item>[] m_ItemTypeItemMap;
private Dictionary<ItemType, float> m_ItemTypeCount = new Dictionary<ItemType, float>();

It seems like I'll need to provide my own custom subclass of InventoryBase that removes this restriction? If so, are there any gotchas to be aware of with how other components expect to reference/interact with the player's Inventory?
 
The player will only ever have one currently equipped item (so only 1 slot), but their inventory is essentially just an array of item instances.

e.g.

Currently equipped:
- wooden spear (6/10 durability, on fire)

In storage (backpack):
- wooden spear (9/10 durability)
- wooden spear (10/10 durability, enchanted)
- iron sword (10/10 durability)
- bread roll (4/10 durability, 2/3 bites taken)
- bread roll (9/10 durability, no bites taken)
- etc.

It's somewhat similar to the inventory system of something like Dark Souls, where you can have copies of the same kind of weapon (ItemType) in your inventory but each has its own durability. This "array of Item instances" inventory system I need seems fundamentally different than the "mapping of ItemTypes to their amount" one UCC provides out of the box. That's fine and kind of what I'd expect since the latter fits the needs of most games, but I just wanted to check that providing my own inventory implementation/subclass of InventoryBase would still work alright with the rest of UCC's components.

If somebody in the community has made an implementation like this, that would help save some time as well.
 
Ah, yes, in that case you will want to subclass the InventoryBase component. The inventory in UCC is extremely simply and it makes sense to extend.
 
Gotcha, I'll proceed down that path then and let you know if I have any questions later on about integrating it with UCC.
 
Top