Unequip Duplication

MrQuaid

Member
Hi, I have my inventory set up with a 16 slot limit on all items, no limit on stacking. That part works fine I can pick up items and when full I cant. The issue I have no is when I equip say a shirt and then unequip it, it duplicates the item and drops it onto the world. The same shirt in my inventory now does nothing when equipped, but can be dropped. Also I noticed in the main inventory on the player, the one I limited to 16, even if I pick up more it goes there just with negative numbers.
 
Ok, so I got it to somewhat work, by doing force remove instead, which works fine unless I have a item equipped, if I have a full inventory of 16 items, equip one, I can then pick up a new item.

I could not get the reject items action to work, I even created a rejected collection which it duplicated the item but never removed from main inventory.

I am not sure the intended way to set up a slot limit on items, perhaps I am doing it wrong, I just want a size limit of 16 (something), and not be able to add anymore when thats reached. Ideally, I would like my item to move from my bag to equipment slot, but if I can at least get it to not add more when bag is full and items equipped.
 
Interesting, that seems like a bug with the item restriction. It may be caused by the order items are added/removed when equipping/unequipping... I will look into it in depth later this week. I'll let you know once I find a solution.

In the meantime if you want to try solving this problem on your own you could try writing a custom restriction script:

Or if you want to have total control you can write a custom Item Collection:
 
Thanks for looking into it, I will try to work with a custom restriction script, I can program but still learning the more advanced things.
 
I'm looking at this issue again.

Just to clarify you are trying to make a limit of 16 items + equipped items or 16 item including equipped items?

If it is the later I believe all that was missing was setting the Restriction Item Collection IDs to also monitor the "Equipped" Item Collection.

If you are trying to achieve 16 items + equipped items then the approach you took is the correct one.

In either case you would still get the bug you encountered. I was able to replicate the bug where negative amounts of item is being added to the inventory. I haven't found the solution just yet, but once I do I will let you know. Even if I do find the solution it may take a while before we make the next update. So I would still advise looking into a custom solution like I mentioned before. Do let me know if you struggle with that and I'll help guide you towards the useful functions.
 
The bug is now fixed, it required some changes to the GroupItemRestriction, the Inventory component and the MoveToCollectionItemAction.

There were actually a few issues...

Thank you for reporting this issue, the fix will be part of the next update
 
Thanks for the quick update, right now I'm early in development so I can wait for the next update, however, if I attempt to create my custom script I may reach out to you for some tips. Thanks again, this asset is really great.
 
Hi, just some more info, you might have already solved this, but when buying items, it will duplicate too if you have limited inventory. Just calling out incase you didn't look at that too. Take care.
 
Thank you for letting me know I will look into it (as you said it might already be fixed, I haven't tested it yet though)
 
Hi, just updated and the inventory pickup bug looks to be fine now for picking up inventory items when the inventory is full. I did however find another one, if you try to take an item from storage when you have full inventory it duplicates the item. Does no go in inventory just drops on the ground. Also when you buy an item and have full inventory it drops on the ground which isn't terrible unless it clips into an object. I believe crafting does the same.
 
...humm I see, that is a problem. All of these menus add the items in the inventory without checking if it still has space.
But even if I were to check that the inventory had space it would trigger the item drop because the GroupItemRestriction triggers a "reject" in the "CanAddItem" function...

I'm afraid I oversimplified the restriction process... Until I refactor it to allow more control, I'll have to advise you to create your own custom restriction.

You can check the itemInfo to know where the item is coming from, if it is coming from the Storage or Shop you can deal with it, if it comes from somwhere else you can drop the item like you are doing now.

I'm sorry I cannot help you more than that right now, I will add this to my list of things to review. but it seems like it will require a pretty big refactor so it may take long time before I can get to implement it.
 
I understand, would you be able to help with the custom restriction script? I'll try to implement it myself first but might need some guidance. Thanks again.
 
Hi, so I managed to modify the CategoryItemActionSet to check if the item has a storage item collection, if so it does nothing. I couldn't figure out the shop, but it's ok the item just falls on the floor so that's fine.

Did find a smaller bug, sometimes the items spawn to close to the ground and fall through, is there a way to increase the random height so that doesnt happen?
 
Ah I hadn't thought of that.

I added a center offset field to the drop action

Code:
[Tooltip("The center of the random drop radius.")]
[SerializeField] protected Vector3 m_CenterOffset;

So now the position of the spawn is computed like so:

Code:
gameObject.transform.position + m_CenterOffset + new Vector3(
    Random.value * m_DropRadius - m_DropRadius / 2f,
    Random.value * m_DropRadius,
    Random.value * m_DropRadius - m_DropRadius / 2f)

Feel free to change the source code which will be updated in the next update or copy paste it and create a custom drop Item Action which better suit your needs
 
Top