I have facing some issues with saving/loading inventory.
I am loading “PlayerInventory” as text and then as a scene variable.
And then using the variable to update the text:
The inventory is loading properly in both scene and global variable (as confirmed in Debugger). However, it is not updating the text with that value.
When the variable value changes, it refreshes all the values with “0”, and then update the text and save the new value.
For instance, if the previously saved value was 10, trigger to save the new value changes it to 1. The saved value persists even after the scene restarts/reloaded, but the text representing that variable is not updated with the value.
Here’s the screen shot of the values as shown in debugger and preview.
After saving the changes (changes are made to Water and Bullets):

SceneVariable:
Global Variable:
After closing the preview and reloading the game (changes persist in debugger only; values resets for all the children):

After saving the changes(saved value lost to new value; changes reflected in both debugger and preview)

In case it is useful, here’s the save events for the same.
Please note that I add the Global Variable “GlobalPlayerInventoryVar” only to check if there’s any mismatch between the values. I tried replacing scene variable with global variable to update the text values on loading the scene, but the result was the same.
I’m not at my pc, so it’s tough to see or test but when the intentory is loaded, isn’t it already in the json format? It looks like you’re converting json to json.
Thank you @Keith_1357: I changed the action as below, but it makes no difference. 
Ok I’m almost positive the global variable is being overwritten. Because you have it as a string, but you make at least one call to it that I see (in the modify water text) that calls it a structure variable with child Water.count. So what that does is overwrites the string and creates a structure with child structure Water with child count and assigns count a default value of 0. Then when you save it, the event calls for that whole structure to be overwritten with ToJSON(PlayerInventoryVar). So on loading it looks like a normal string once again.
Not sure what is going on with the bullets text since you are calling for the value directly from the inventory system. I have never used the inventory system. Have you tried loading the inventory directly from PlayerInventoryVarText and not from the structure you converted that to into PlayerInventoryVar? Maybe the Load inventory command wants a string that it then convers itself? If so then it won’t know what to do with a structure and will scrap everything.
But also Keith is right about the ToJSON.
I have little experience with the “inventory system” myself. It took me awhile to get it working. This is what works for me. I used 3 buttons and a text object to test it. I added an extra step to the save to balance and try to debug.
Edit: I honestly don’t know how this relates to why yours is not working. This is more a proof of concept to verify that this part works.
@Keith_1357: Thanks for the inputs. I am doing exactly as you are doing. To test the inventory, I am using three buttons (two for adding different items and other for removing/equipping them), but the problem seems to be somewhere else. Even when I disable the buttons and do nothing, I am not able to persist the data in the UI on reloading the game. I have no clue what is causing the issue.
Can you post your current events that relate to this as one screenshot(s). It’s tough to get context and the sequence of events with little snippets or without seeing the conditions. I think we need to see the bigger picture.
The very last line isn’t a subevent. So, it will run on every frame. This isn’t good with storage. Storage uses more resources, especially at 60 times per second.
I believe the issue is that when it runs the first time, it’s converting the variable to JSON. Without any conditions, the last line is also trying to convert it to JSON, which is resetting the storage. I think if you make it a subevent, it should work with the save button because that event isn’t converting the variable to JSON.
@Keith_1357: Thank you! Making the last action a subevent of “Save is pressed” did the trick.
Do you mind elaborating on “Storage uses more resources, especially at 60 times per second.” Are there any recommended things to keep/avoid to efficiently use storage usage?
1 Like
Without a condition, the save would’ve happened about 60 times (frames) per second. More is involved with saving and loading storage. So, it could cause the frame rate to drop especially if you were dealing with a lot of data. It’s recommended that saving/loading is done sparingly. The recommended times are opening, before closing, scene changes, end of levels, checkpoints or even a timer, I guess.
1 Like
Thank you @Keith_1357 for your guidance 
1 Like