Inventory weight problem

(Alex) #1

Hello everyone, I have another problem)

The problem is to save and load the weight of the inventory.
When I load my game, I always have a weight of 1 or 5 less than I was in saving.
What could be the problem? I am using Unity 2017.3

(Leslie Young) #2

Weight is not saved but calculated when you ask for the value via a Block like “Items >Bag > Current Weight”.

How and when are you getting the weight of the bag. Maybe you are asking for the weight too early? Restoring game state happens during the Unity Start event so it is easy to try update UI while some things are not yet properly loaded. On Actor Restored could be used as a trigger for when something like the player bag should be ready and loaded.

(Alex) #3

I getting weight when the inventory window opens.
Other manipulations with the weight, I do not spend.


(Leslie Young) #4

You are asking for “Currency” with that Block though.
Currency is gold/coins/money.

(Alex) #5

Oh,I did not notice this. Sorry, I was stupid)) Thanks!

(Alex) #6

Checked now, this was not the screen. Here is the new screen with blox
When saved weight is 8, and I when loaded 7.5 .


(Alex) #7

I noticed was it works correctly when all the items In bag are 1 each in Stack. And when for example 2 items in a stack weighing 0.5, then only 1 item from stack is considered, and the weight becomes wrong.

And then the weight becomes not 8, but not 7.5. I think, because I have in my bag 1 items with a weight of 5, another 1 items with a weight of 2, and 2 items with a weight of 0.5.

(Alex) #8

I tried again. Added 2 items in a bag of 2 pieces each. the first item weighs 1, the second weighs 15. (both items are 2). I was saved with a weight of 32. It was loaded 16. Exactly half, that is, only 1 item from the stack is considered.

(Leslie Young) #9

So it seems stacked items are the problem here?
I’ll have a look.

(Alex) #10

I think yes. Because when I save game without stacked items, it works fine and the weight is correct.