Looking for a way to drop all items when bag is dropped?

I have a simple inventory setup so that when I pick up a bag it adds 8 to 20 slots to the inventory UI and when I drop the bag it takes away the amount of inventory spaces, it’s working well but the problem I am having is that the items are still there when i reattach a bag and i need them to drop when i drop the bag and stay when I get a better bag?

Not sure how to remove all & drop all items from index or inventory

Spawn all items when bag is dropped?

Are you looking for the node “CLEAR” array? This will remove all elements in the array of your inventory.

That worked for clearing the inventory thank you, How would I drop all the Items that I am carrying in my Bag/Inventory before clearing?

Screen shots would help here. And more clarity on what you mean by “drop” items. Like delete them? Or move them to another location? Need to see your set up to help further.

Drop all items from inventory Spawn all items in the world in front of player on the ground before CLEAR is triggered so the items spawn in front of the player! so basically removing all items from inventory before clearing to spawn them into the world if the bag is dropped or downgraded

Just use a for each loop and spawn each inventory item then clear the array.

I have managed to get the ForEachLoop to work “kinda” but its not spawning all picked up items from the inventory tried it a few times now and it seams to be only dropping the last 3 items that I have picked up? any ideas why this could be happening?

Screen shot?

Still, I have never seen your code so it helps me to see EXACTLY what is happening. You may think it is the same but obviously something isn’t working right and because you stare at your code all day it may not be obvious to you a small change. Hence fresh eyes, if I take your word that everything is “exactly the same” then you limit what I may be able to identify looking with a new perspective. It doesn’t make sense to only dump 3 items if there are more in the array so something is up. A screen shot of the whole set up would help me help you ha

its just the same as the Screen Shot above, Just with a for each loop and drop item function… Been playing around with it but nothing is working

I just need to make a function to drop all items from my inventory including stacked amounts,

Just got back and added the same things I did before after playing around I managed to get all the items to spawn apart from items that have more than 1 in a stack, and I get a runtime error because how I set it up it looped back round to ForEachLoop and it was trying to keep taking what wasn’t there but obviously I’m missing something :confused:

What is the error? Haha

First of all, I’d say that using Array for the bag is not the best solution, because you can move things around in the bag and some slots may be empty while some slots after the empty ones can be filled, and arrays don’t allow that. It would be a good idea to use Map (Dictionary) type of collection instead.

But be careful in this case: if you put one item in Slot 0, and another item in Slot 2, the Dictionary Length will be 3, not 2, even though Slot 1 is empty, so you should account for that whenever you get its Length to see where you want to put your next item.


What I imagine for dropping items: Let’s say you have your main bag that can contain up to 20 items. It’s Dictionary keys will be 0-19.


Case 1: you drop your additional bag.
1) You check how many items (Dictionary Values) it contains (again, simple Length will not always return the correct result since you can move things around in the bag). You may make a temporary array for them.
2) You check if you have empty slots in your main bag.
3) You transfer a number of items from the additional bag to the main one, and the rest you Spawn in front of your character and Clear the temporary array.


Case 2: You pick up a smaller additional bag.

  1. Repeat 1) as per above.
  2. Depending on your preferred logic, you may either leave the starting items in the new bag and transfer the rest to the main bag, or vice versa. I’d say the first one would be more player-friendly.
  3. You transfer your items to the new bag and some to the main bag if it has room available. The rest you drop.



    You can use different Dictionary for different bags, but you can use one for all of them at once. It might be a little tricky if you plan to have more than one additional bag, because if you change Addition Bag 1 for a larger of a smaller one you will have to change the Keys for your subsequent ones, so maybe having a separate Dictionary for each bag would be easier. But again, when you have to look for a quest item, for instance, that you have to remove from the inventory automatically, you will have to look through all the Dictionaries instead of just one. So it depends.

This error only comes up when I connect the for each loop back on itself after drop item but that way it drops all the items until there’s nothing left then goes to complete when the no bag bool is set to true… that is a none issue, because when I do that it’s trying to clear items from the inventory that isn’t there which causes The runtime error

Screen shot of the error??