Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.18
more ▼

asked Aug 19 '18 at 08:00 PM in Blueprint Scripting

avatar image

8 1 4

avatar image Nebula Games Inc Aug 19 '18 at 09:45 PM

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

avatar image AndFlukey Aug 20 '18 at 01:58 AM

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?

avatar image Nebula Games Inc Aug 20 '18 at 02:24 AM

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.

avatar image AndFlukey Aug 20 '18 at 03:15 AM

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 alt text

unattachbag.png (163.6 kB)
avatar image Nebula Games Inc Aug 20 '18 at 03:18 AM

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

avatar image AndFlukey Aug 23 '18 at 02:39 PM

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?

avatar image Nebula Games Inc Aug 23 '18 at 02:40 PM

Screen shot?

avatar image AndFlukey Aug 23 '18 at 04:31 PM

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,

avatar image Nebula Games Inc Aug 23 '18 at 04:38 PM

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

avatar image AndFlukey Aug 23 '18 at 08:16 PM

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 :/ alt text

foreachloop.png (541.3 kB)
avatar image Nebula Games Inc Aug 23 '18 at 08:28 PM

What is the error? Haha

avatar image AndFlukey Aug 24 '18 at 05:21 PM

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

avatar image Nebula Games Inc Aug 25 '18 at 07:03 PM

Screen shot of the error??

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Aug 24 '18 at 05:02 AM

avatar image

1.8k 12 7 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question