x

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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Inventory Item Stacking

Hello guys I have an inventory system with Add Item if there is no in the Inventory(Array) and if exists change the values of this item.

The only problem i have is that when the Item Exists I can't find the item in the array and change it with the values of the hitted item(Line trace)

This is the Blueprint if the item doesn't exist. Takes all the values and add it to the Inventory(array) 1

And this is the Other side of blueprint that doesn't work ...

2

Product Version: UE 4.21
Tags:
2019-03-07-1.png (255.2 kB)
2019-03-07-2.png (230.7 kB)
more ▼

asked Mar 07 '19 at 12:49 PM in Blueprint Scripting

avatar image

THT_Nick
19 1 2 3

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

1 answer: sort voted first

there are several problems with your second picture.

the first issue is that your not actually doing anything with the loop. currently your only setting a inventory array element on loop complete. the next issue is your not actually using the new items information or incrementing a specific indexes qty.

anyway below is an example of how this kind of thing could be done. i did it in the pickup itself and as a function. now how this works is that i get the player so that i can get their inventory, then i run a loop which checks if there is any item in the inventory with the same name as the pickup. if the item exist in the inventory then we need to check if it stacks, if it does then we add one to the quantity and set the array element. then we set the found item bool to true and break out of the loop since found what we need. if any condition here fails then we just move on to the next item in the inventory. when all items have been checked or once we break out of the loop then the loop completed will run, at which time we check the found item bool. if the found item is true then we know we have already added the item to the inventory, but if its false then we need to add the item to the players inventory via the add node. once all thats done we can safely destroy the pickup actor.

im sure it looks complex since its a bit messy but its pretty simple, your just doing a series of checks really.

alt text

capture.png (352.3 kB)
more ▼

answered Mar 07 '19 at 04:05 PM

avatar image

ThompsonN13
10.1k 33 9 23

avatar image ThompsonN13 Mar 07 '19 at 04:08 PM

oh and i should also note that when you try to use something like a contains node on a struct you may run into issues where all variables in the struct need to be identical to actually be "matching". so you could have something with the same name and stackable bool but if the quantity isnt the same then it may not recognize that the array contains the item since the item is technically different.

avatar image THT_Nick Mar 07 '19 at 04:48 PM

Ok Guys I will try to change things and see if it works

avatar image THT_Nick Mar 07 '19 at 05:05 PM

Thank you Guys That worked :)

(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