Item Collections question

Szymon Z.

Member
Hello,

It's more like "to be sure" questions, but very important to me, because while in the future we want to work a lot with item collections i have to be sure i understand everything correctly :)

1. Item in multiple Item Collection
According to the documentation i can create many of the collections. And as far as i know i can have same item in multiple item collections yes ? And to have one item in 2 collections have i to call itemCollection.Add / itemCollection.Remove ? Can i add item to multiple collections just after pickup an item ?

2. Item Slots only for specific item collection
(I know there is a tutorial about this but i have to ask). For example if i have 2 Items Collection: Big Weapons, Small Weapons. And for example 2 different UI for inventory for each of them. So if i will pres B i will open inventory for Big Weapons and S for Small Weapons. I know i can create a filter by category but what i want to achieve is i want to have my slots container in every inventory and auto-fill with items from specific item collection or from multiple items collections (selected in inspector, i know this part can require some extra code). So the main question is can i use Item Collections as a "filter" to auto fill item slots ? I know there is something like Restrictions, is it correct way ?

3. Item Collections and Equippable in Integrations

Last question for now -> is item collections connected with Equip in Character Controller ? For example if i have Equippable SLots item collection and i can equip ONLY items from this collection. I know there is Item Set Manager in UCC, so what's the relation between those 2 this if any ?

Best Regards !
 
1)
Unique/Mutable & Immutable Items cannot be in multiple ItemCollections. This is a restriction we added to prevent unwanted behavior by most users.
If you try adding a unique item to an ItemCollection when it is already in one the item will be dupplicated and given a new ID to make sure they are differentiable.

Common/Immutable Items always have the same ID, so they can be in any ItemCollection in any quantity.

Common/Mutable items are a bit more rare, they also cannot be added to multiple ItemCollections, but they can be added multiple times in the same one.

If you are confused about Mutable/Immutable/Common/Unique, perhaps this can help:

I hope that makes sense.

Note that you can override this default behaviour by creating your own custom ItemCollections. We added those restrictions mainly to prevent accidental unwanted behavior from inexperienced users. But if you know what you are doing then you might want a different behavior.
Making custom ItemCollections gives you complete control on how items are added/removed/stored in your inventory.

You can mix and match differente ItemCollections of differente types. Here is an example from the Adventure Kit project I am working on:
1626162917884.png
As you can see I use 4 different types of ItemCollection.

2)
Yes you can, I do it in the Adventure Kit. Here is how my filter looks like:
1626163250562.png
Here I've set the filter on a tab, but you can set the filter directly on the InventoryGrid instead.
The filter I am using is the "Item Info Item Collection Filter"

Don't forget that you can create your own Filters if you want to, and you can also combine existing ones using the "Item Info Multi Filter"

3)
In the UCC/UIS Integration we use "Equippable" ItemCollections. These can be any type, they don't have to be ItemSlotCollections. "Equippable" ItemCollections are defined on the bridge component like so:
1626163888837.png

Any Items added to those ItemCollections will be automatically added to be processed by the bridge component. If any ItemSetRule matches the Items in the Equippable ItemCollections then an ItemSet is created which can be equipped/unequipped at any time.
When the item is removed from the "Equippable" ItemCollections then the ItemSetManager checks the ItemSetRules to see if any ItemSet needs to be removed.

When an item is in the Equippable ItemCollections we say it is "soft equipped"
When the item is inside the active ItemSet we call it "active equipped"

You can find more about the integration here: https://opsive.com/support/document...oller/integrations/ultimate-inventory-system/
I'd recommendyou read the first few paragraphs, especially "Terminology" and "Concept". It'll give you a good basic understanding of our design and why we chose it.

I hope this helps :)
 
Okay, this making some things cleaner but now i have more questions than before :unsure:

So if i have an flask of potion. And some flasks should be equippable, some of them not. Flask should be in item collection "Consumable" and for example "ForSellCollection". Plus because that should be able to equip to hand this should be also equippable. So if i understand correctly this is not able to achieve with opsive right now and we have to write our own implementation of collection system if we want to achieve this ? :eek:

I know there are item categories and we can try to work with that, but then we will have to change item category dynamic by code instead of switching item collections... Is it right ?
 
I'm not sure I understand your use case.

If you have a flask which is equippable on the character hand. Then it would go something like this

pickup flask -> flask in "Usable ItemCollection" (or equivalent: main, consumable or any other name you want for that itemcollection) -> "soft equip" flask -> moves flask to any "Equippable" ItemCollection, the flask is no longer in the "Usable ItemCollection" -> "active equip" flask -> the item set with the flask becomes active -> sell flask -> flask removed from the "Equippable" item collection, therefore it is unequipped.

You do not need a "ForSellCollection", don't forget that ItemCollections are only there to help you organize your items into groups at runtime, don't confuse them with ItemCategories which are used to organize items in edit time. An Item can be part of many Item Categories because ItemCategories can be nested and have multiple parents.

The way you show items in the UI is completely up to you, in some places you can use an ItemCollection filter, in others you can use a category filter, you can use a combination of the two, or even create your own filter.

Just to clarify you cannot change the category of an item at runtime.

Lets say I have a category called "Consumable" that item category could have many parents: "All", "Sellable", "Usable", etc... each of these categories are things that you create to organize and give functionality to your items.

In the Shop Menu you could add a filter to only show "Sellable" items, no need to create an ItemCollection for it.

Think of ItemCollections as bags where you put your items inside. An item cannot be in multipls bags at the same time. Even though your flask is in a single bag it is still "Sellable", "Usable", etc... since it is a "Consumable".

Item Categories are the essence of the item, is defines what it can and cannot do
ItemCollections are used to store items.
Inventory Grids shows whats inside an Inventory and you can use filters/sorters to customize exactly what you see.

Don't forget that if you wish to change an item at runtime for whatever reason, you can use Item Attributes. This is only really used when an Item is Mutable and really needs to change. For example in the integration demo we use an Item Attribute to store how many ammo is in the clip.
You can use Item Attributes for any other reasons, but don't over do it.

Perhaps you should watch the first few video tutorials: https://opsive.com/videos/?pid=22330&video=22930
and read the getting started documentation: https://opsive.com/support/document...y-system/getting-started/defining-attributes/

If you really need items to be in multiple things at a time which can change at runtime, then perhaps I could come up with a new object that I would call "Item Groups", that would work in parallel to ItemCollections, but I really don't think those are necessary. If you can find a good use case for it I'll add it to my TODO list (note that it would take a long time to implement this)
 
I saw videos and documentations, we are working on it with group of developers and we are trying to build game architecture around your solution and it's why im asking so much :)

Our use case => Player has a flask. Now player want to mark it as "sellable" and in multiplayer component other players can get "sellable items collection" from this player and buy something. We can probably do it by adding category with bool "OnSell", but we thought item collections is something what we can use to store some stacks of items. But still, if something is in bag "sellable" should be still in bag "quick-items" to allow players quick acces to those items (even if those are able to sell). So now it's not possible, if player will put item to "quick slot" a'ka "Hotbar" he cannot put it to "OnSell" item collections. While we wrote our own tool to parse CSV data to create/edit items and its working fine, we want to make it as simple as possible. Instead of switching the bool of item category, we want to put item to the bag, exactly like u said :)
Another example, we want hotbar items collection. And we have flask in hotbar. But in another place in our game we want to show all "Consumable items collection". Now item is in hotbar collection so it's not possible to sort by Consumables. We have to choose if we want this item in hotbar collection or in consumable collection... so it's hard to think of it as a group of items. I hope now our use cases are clear. We exactly want to do what u mentioned: organize items in clear way without complex categories :) Just build the condition based on ItemCollections and get items from the collection. But not from single bag. I think this is best example:
- We have item collection "Sellable" (we can image this is a bag when player can put some items)
- We have item collection "Hands"

Now we have sword in right hand and shield in left hand.
We met another player.
He can get access to item collection "Sellable". But we also want to be able to sell our sword (but not the shield). So we cannot add collection "hands" as able to sell, BUT we probably want to add "Sword" to second collection => Sellable.
Now player we met can buy everything from the Sellabel bag + from our hand (but only sword, because shield isnt in sellable collection). But while Equippable collection is Hands, sword cannot be as Sellable only, because it has to be equiped => so it has to belongs to "Hands" collection
 
I see that's an interesting use case... It's not something I had in mind.

I would go a different route than ItemCollections for this. The ItemGroup idea I talked about above would be the way to go I think.

Just to clarify one thing. The ItemHotbar does not need to have its own ItemCollection, each slot can point to any item within the Inventory, no matter its itemCollection. My custom solution for you will function similarly, you can have a look at the ItemHotbar script to get some inspiration.


The player needs to decide what Items are sellable and which are not manually, right? So what you could do is add a new custom Component, lets call it "ItemGroupManager", on your character, next to your ItemUser and Inventory components.

In that component you can add a Dictionary of <string, List<ItemInfo> > called "ItemGroups", where the string will be the item group name.

You can create a custom ItemAction to let the player choose what groups the item should be part of.

You can listen to the event on the Inventory to know when an item is added/removed from the Inventory. You can use that event to update the content of your ItemGroups, whether its removing the items that no longer exist in the Inventory, or inversely add items that were just picked up.

The last things you'll need is a custom Filter that needs to get the information about the ItemGroup. Since the ItemGroupManager could be next to your Inventory than you should be able to get it fairly easily from anywhere using the InventorySystemManager.GetInventoryIdentifier() or using the ItemInfo.Inventory.


If I were to implement this myself I would make it a bit more complex such that it could be easier to modify/extend but this gives you a rough idea to go on. Add I would probably link ItemGroups to the Inventory add a way to access the ItemGroups easily from the ItemInfo.

I'll add this feature to my TODO list, I'll need to think about it more before I start implementing it.

I'm sorry there is no easy solution to your use case built-in.
 
Okay, I understand.

Just I'm wondering how did u solve the use-case where for example You have Inventory UI and you have 2 slots container inisde. One is Grid Inventory (with all the items) and second one is hotbar (next to inventory). Then if u will put an item from inventory to Hotbar, it shouldn't be visible in inventory grid anymore. And back to inventory grid if i will replace this item in hotbar with another one. My idea was just to use 2 collections:
HotbarCollection and InventoryCollection, but if item cannot be in 2 collections in one time, this is very problematic
 
You are confusing ItemViewSlotContainers with ItemCollections.

ItemCollections stores your item in the Inventory.
ItemViewSlotContainers are UI elements that show ItemInfos, no matter where they are from.

The InventoryGrid shows items within an Inventory in all ItemCollections
The ItemSlotViewContainer (aka Equipment UI) shows the items within one ItemCollection (of type ItemSlotCollection)
The ItemHotbar shows any Item you assign to it with an option to remove them automatically if they are no longer in the linked Inventory

For example, in the UIS demo scene I only have 3 ItemCollections: Main, Equipment, DebugLoadout.
And if you test it you'll see that the hotbar works just fine, it mirrors items which are inside the Inventory without moving them. So the item appears both in the Inventory Grid and the ItemHotbar.

I hope that makes sense.
I've added the ItemGroup feature in my TODO list and wrote a few ideas, but as i mentioned before it will take a lo of time to implement and modular and extendable solution. Sorry for the inconvinience.
 
I think we arent on same route ?

I know the relation between ItemViewSlotContainers and ItemCollections. I know that the ItemViewSlotContainer contains items from specific collection. And this is why im asking :)

For example your demo scene, You have 3 collections: Main, Equipment, DebugLoadout. To make it sense, let's add third collection, lets say Consumable.

Now 3 ItemViewSlotContainers.

First one should contains items from Main Collection
Second one from Equipment collection
Third from Consumable collection

Now i have a flask. At the start Flask should be visible in First Container (items from MainCollection) and third container (Consumables).

Now i will drag flask from FirstContainer to SecondContainer. And because of that i dont want to see flask in main inventory (first container) anymore. Now it should be visible in second and third container. So if first container contains only MainCollection, the easiest solution will be to move item from Main To Equipment Collection. But still should be visible in third container (because still should belongs to Consumables). I hope is it clear ?
 
I know that the ItemViewSlotContainer contains items from specific collection. And this is why im asking
That's not correct, ItemViewSlotContainer can show items from anywhere, they do no have to be in any specific ItemCollection.
You might be confusing the "ItemViewSlotContainer" with the "ItemSlotCollectionView" because of a typo I made in the previous posts, I apologize.

The name ItemViewSlotCotainer comes from:
ItemView : A component that shows an Item in the UI with modules to show icon, image, selection, attributes and much much more.
ItemViewSlot: A component which is a improved Button, receives the usual Unity UI events such as select, click, etc...
ItemViewSlotContainer: Multiple ItemViewSlot Indexed such that they can be used to show multiple items

In the use case you mention above you do not need a third collection.

Lets ignore the DebugLoadout ItemCollection since its irrelevant to your use case.

You can have 3 ItemViewSlotContainers:
  1. Main Inventory Grid
  2. Equipment panel
  3. Consumable Grid
and 2 ItemCollections
  1. Main
  2. Equipment
The Main Inventory Grid can have a Filter to only show items within the Main Item Collection
The Equipment panel can use the "ItemSlotCollectionView" (aka Equipment View) which shows whats inside the Equipment Item Collection
The Consumable Grid can use a Filter to show All "Consumable" Items within the Inventory (or a subset of multiple ItemCollections) So it can show items that are both in the Main and the Equipment collection.

I'd recommend you check the UIS Demo again. Despite having just two ItemCollections, I use 4 ItemViewSlotContainers:
  1. InventoryGrid (With multiple tabs filtered by category and ItemCollection)
  2. ItemSlotCollectionView (to show the equipment)
  3. Hotbar (to show items assigned to the hotbar no matter whether it is in Main or Equipment ItemCollection, I actually use the hotbar to equip unequip weapons)
  4. ItemShapeGrid (Shows all the items within the main item Collection, it also restricts the size of the main itemcollection)
Let me know if you have further questions
 
Top