Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ERedXIII · Oct 23, 2015 at 12:29 PM · jsonarchitecturestorage

Store game objects in a JRPG game

I've come up with this approach so far:

I have hundreds of items(let's say guns) which i store in a JSON file. Whenever the game needs to use them they are called. So my question is: Is this a good way to go? A JSON file with all the guns data? Or maybe I should serialize them and store them in the JSON file better? If you think there's a completely different and better approach I'd like to know it. I'm looking for best practise and most consistent way to do this.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Epicwolf · Oct 27, 2015 at 12:36 AM 1
Share

I'd say it depends on what you are using the JSON file for.

If you're using this JSON file as a sort of non-editable "database" of every possible item type in the game, I would consider creating a Item class with many sub-classes, each representing a different item. There are multiple ways to instantiate the individual gun classes, like having a method that returns a certain item instance based on an ID of some kind (use a big switch statement?), or you could maybe create instances based on the class name as a string. Whatever makes sense for your game and is more efficient.

If the JSON file represents the player's inventory or some collection of items (that isn't a complete list of every item in the game), you could create a serializable class that simply stores a list of items and serialize that, or simply continue to parse JSON data to load the collection. Both would work fine. (but it would be harder for a user to edit the serialized file)

avatar image ERedXIII Epicwolf · Oct 27, 2015 at 10:40 PM 0
Share

That's the way I've done it so far. I have a baseItem class. Then i derive this class for the different types of guns, etc. And I store each gun's info in a JSON file. And, to save, for example the current inventory, i save the item's ID and then i retrieve the data and load it into the different type of classes at the end of the scene when needed.

But I'm not sure this is the proper way to go.

Thanks for your answer @Epicwolf.

avatar image Epicwolf ERedXIII · Oct 27, 2015 at 11:07 PM 1
Share

If you have classes deriving from BaseItem that represent different item types, why do you need to store each gun type to a file? It seems to me that using a JSON file would be only necessary when loading saved character data (like you do with the saved IDs) or something similar. If you are saving the current values of each item's fields in the player's inventory to one file, and saving the IDs of the items in another file, (which it sounds like you are doing) serializing all the items in the inventory (or the inventory itself) would make loading data much simpler. From what a few quick Google searches and some Unity Answers questions tell me, this class-oriented approach (with serializing of items/inventories) seems to be the popular choice, and it sure seems to be the simplest.

avatar image ERedXIII · Oct 28, 2015 at 09:12 AM 0
Share

I think i didn't explain myself really well, sorry. I have a baseItem class and then i derive it to weaponItem, ringItem, bootItem, etc. And from each of these general types, more types are derived. But, let's talk about weapons for example. I have 40 different swords, let's say. Each sword deffinition is stored in a JSON. weaponsJSON consists of different arrays one being all the swords deffinition for every sword in my game. And when i save data i save the ID and then when needed i instantiate every weapon filling the objects with JSON data called by ID. I don't use serialization since I've done this approach on saving just the id. Should I store the objects serialized ins$$anonymous$$d of just keeping track of the id? Thanks

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

is LitJson still best for storing Json data for unity? 0 Answers

Modifying Json file values 2 Answers

How To Separate Json Parameter Function to get values i need ? 0 Answers

Is there something wrong with Application.persistentDataPath (on Samsung s6 running Android 5.1.1) ? 1 Answer

Android App stopped asking permission for internal storage 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges