❔ Inventory item stacking
i am working on a inventory system in unity where i am trying to add item stacking, however i am having issues where its not displaying the correct number of items that are stacked. , i managed to spot something which might be the main reason why items are not stacking properly.
so whenever i am incrementing items, the item count goes up as expected however when i click on the inventory icon, the values reset for some reason
not really sure how to fix it.
18 Replies
here is the issue
that is some really rough code to read firstly
you are calling "incrementcounter" in so many places that i have no idea how your program even logs the correct amount
it most likely has something to do with the "Count" component on your display
look at ListItems
are you actually setting the correct Count(internal variable) to the item's count display?
cleaned up the code @pip
yes i am
let me triple check
yea i am
so you're only updating the text when the object is initialized
create a new function "UpdateText" with that same code
and call that when you open the inventory
easy
like this ?
i did this before but it didnt help
maybe set it active first
then set the text
still no luck : (
@pip should i call the UpdatedText here in the Add function?
sure, try it
you know your code better than i
Ahh gives me a null reference error
I tried putting "UpdatedText" inside update function and still same issue
I genuinely don't see why the count value gets reset
why not just have Item have a property called Count which you could implement
instead of relying on this inventory controller
you could do something like this
you may need to implement further logic to account for newItem stack size and compare the current item stack size to see if you need to create a new stack
but you get the idea
so i did something similar where i have count implemented in my inventory manager instead of relying on inventory controller so that i dont have to worry about inheriting issues and the issue i have right now is that items no longer stack when adding them, the count value in the log is correct since there are 8 items in the list but they still display as 1.
here is the updated code
the count or stack size should really be the responsibility of the item
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.