Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a Painless Inventory System with Scriptable Objects in Unity #4

Toqozz opened this issue Feb 26, 2021 · 3 comments


Copy link

Toqozz commented Feb 26, 2021

Discuss the blog post here; share your thoughts, improvements, or any issues you run into so that others can find them.

Copy link

Thank you so much for the post! I changed the array to a List and am now having an issue that if I output the inventory instance, the list is there, but when I try to access the List inside it, it is empty. Do you have any idea why this could be the case?

Copy link
Owner Author

Toqozz commented May 1, 2022

Hmmm... this could be a few different things, and it's hard to really narrow it down without seeing any code.

Is this a save/load issue? Does the inventory work normally at runtime but doesn't "remember" stuff between runs?

A good guess would be that I think List may not be serializing/deserializing the way you'd expect. Understandably when loading from JSON I think it just parses every "list of elements" as an array, and I'm not sure that there's any magical conversion there. You might have to load the JSON then transfer it into a list or something weird like that.

The best thing to do probably is to put a breakpoint in the get instance code (Inventory.cs:L11) and the save/load (`Inventory.cs:L34/L41) and take a look at the variables to see exactly where things are going wrong. Also have a look at the save file itself and make sure things are getting written out.

If it's a runtime error... I'm not sure. Make sure you've updated all the insert/etc methods to use a list as well?

Copy link

Thank you for your response! The issue was that it is impossible to serialise just the list on its own. I created a wrapper-object for it, and the serialisation worked. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants