Inventory Item Collection Restriction [Help]

Exi-G

New member
I am using the Item shape inventory grid and i have multiple item shape grids (e.g. Backpack item shape grid which uses the main inventory item collection and Vest item shape grid which uses a separate inventory item collection (Vest)). I want to restrict the main item collection (backpack) to add item to the vest item collection when there are no space in the backpack inventory grid.

I am using the GroupItemRestriction and the ItemCollectionRestrictions field has an option for FullSize which works well with normal inventory grid. but for the item shape grid this option doesn't work well because if i set the FullSizeLimit to 4 and i add an item with grid shape of 2x2 which takes 4 grids, it only count it as 1 item.

I want to create a custom Item Restriction which determines the size of the inventory based on the number of grids available but not the number of item stacks. I know the ItemShapeGridData has a property for getting the grid count and also checking if item can be added to the grid using the IsItemValidForGridData method.

I want my custom item restriction to have the same functionalities as the GroupItemRestriction but just add the option to restrict based on the available grid spaces in the inventory. I was thinking of inheriting the GroupItemRestriction class but i am not sure the proper way of add the functionality i want.

Could you please advice the best way to solve this?
 
Last edited:
I'm glad to see people using the asset to its limits :)

I'd recommend against use the GroupItemRestriction object. It's good for simple use cases but not for complex cases like yours. Additionnally you need to be careful when using the GroupItemRestriction object, I made it early in the asset life cycle and realised it wasn't really the right tool for what you are trying to do. It's good for restricting items from being added, but it shouldn't be used anything other than that.

The main issue was that I was calling the Overflow events inside the "CanAddItem" function, which means that if I was just trying to check if the item had to be added (without actually trying to add it) it would call that overflow event.

Since then I added two new things, the ItemTransactionCollection:
And the ItemRestristionSet object:

They work really well toghether. Using the ItemTransactionCollection as your main item collection allows you to transfer items to where they belong/fit. And the overflow events only happen when the item is actually being added and not when I can just checking if it can be added.

In your case though its slightly more complicated because you won't always add items through the main item collection, you might add item directly inside a specific item collection.
I'm afraid there's no good built-in solution for those types of overflows. It is in my todo list to investigate how I could implement this without breaking existing projects. But that will take a while...

There are two solutions to this problem:
1) Use custom ItemActions or DropEvents that do the checking for you of where the items fit and where it should be added depending on where it overflowed from.
2) Create a custom ItemCollection class and write the code to deal with those sorts of overflows.

I think the way I would do it is option 2 since it would work in more cases.

I hope that helps clarify some of your questions. If you have any feedback or ideas on how we could implement this feature built-in it is welcomed.
 
Thanks for the clarification. I will look into it further to see if I can find a way based on your instruction.
 
I had tried with using ItemTransactionCollection for the main collection and added different ItemCollection for Backpack, vest, shirt and pants and it works fine for my use case. the ItemTransactionCollection distribute the items the collections and if there is no space it just overflow to the next available collection as i needed.

Thanks for the help. This actually saved me from writing any custom code. It does what i was looking for even without adding the ItemRestrictions.
 
Top