Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Setzer22 · Dec 27, 2012 at 08:36 AM · arraydatabasexml

Arrays or database?

Hello everyone,

This is more a design question that asking for code. In my game (something like an RPG) I'm planning to have a large amount of items, weapons, armor and so on.

I've designed the item class, and I want the constructor to only take an ID to assign everything else, so i could call Weapon someWeapon = new Weapon(25) and assigns all the other class properties such as name or description from somwhere just by its ID. (Item is abstract and Weapon inherits from it, that's why I swapped names)

So my dilemma is wether to use a class holding all the needed data in Arrays which are initialised at the start of the game or to use some kind of database to hold all the needed values (Let's say, an XML database, or anything else you would recommend).

I don't have that low-level knowledge of how the OS works so I don't really know which is better, but I'd bet that the first one (the array method) is faster in execution time, but has a much higher memory usage than just loading a single Item whenever needed from a database.

I'm trying to keep everything as optimised as possible as I'm aiming into android platform.

Thank you very much!

Comment
Add comment · Show 1
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 Setzer22 · Dec 27, 2012 at 11:50 AM 0
Share

I'm not planning on any kind of online mode for my game

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by MarkFinn · Dec 27, 2012 at 10:01 AM

For purposes of Optimization you will be able to squeeze much more performance out of simple class constructs like arrays (or even dictionaries, though there is a cost over arrays) than over a generic ease-of-use, control and security item such as a database plugin.

Long story short, databases will be easier to update, control, debug and monitor. Home grown simple data structures will be more fine-tune performance friendly.

You pays yer money and you makes your choices...

Comment
Add comment · Show 1 · Share
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 Setzer22 · Dec 27, 2012 at 11:28 AM 0
Share

Ok, seems it is as I expected, I think i'll go on with the class constructs way of doing it.

avatar image
3

Answer by whydoidoit · Dec 27, 2012 at 10:14 AM

While I agree with @MarkFinn I also think that this would also be a good use of a class derived from ScriptableObject - where you could effectively create assets out of your class and fill them in using the Inspector. ScriptableObject subclasses can be added to your project and can be referenced by scene and project items alike. I use this extensively for similar concepts to those you are creating. The benefit is that you have an inbuilt editor in the inspector and many ways to assign other project items that would be a lot of typing and resource lookups from code.

Comment
Add comment · Show 3 · Share
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 Setzer22 · Dec 27, 2012 at 11:30 AM 0
Share

I think this might be a good idea, i'll definetly use it. Thank you very much

avatar image whydoidoit · Dec 27, 2012 at 11:32 AM 1
Share

Yeah, its really powerful. But be aware that it is subject to Unity Serialization rules and hence Dictionaries will not be saved (the same as if it were a $$anonymous$$onoBehaviour). Arrays and Lists are fine as are subclasses that are marked [Serializable].

avatar image MarkFinn · Dec 27, 2012 at 12:44 PM 0
Share

A very good point.

avatar image
0

Answer by 1337GameDev · Feb 13, 2013 at 05:23 AM

I recommend hash tables. Or a linked hash map. I use this (the following site's implementation of linked hash map for c#) for prefab database creation and it seems to work fine. It works very similar to java's implementation of linked hash maps.

http://scottgarland.com/Post/Display/LinkedDictionary_for_C

You can store scripts (or strings of the values joined by a dilimitter and split later) and then retrieve these stored values later. The only downside to this is that working with strings (if done a lot in a frame) can cause performance slowdowns. If you only instantiate objects at start() of game, or every so often, it shouldn't be that big of a problem. Users also expect a game to take a little bit to load, so having a little slowdown (but not over 20 secs) at startup isn't going to cause people to dislike your game if playing it runs fine.

A linked hash map seems very logical here as you want to retrieve something by a key (which is very fast to hash and retrieve). Hope this helps steer you in a direction.

Comment
Add comment · Share
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

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Game Database. SQLite, XML, JSON or PlayerPrefs? 1 Answer

Where will those XML files be stored if the platform of this game is Web Player...? 1 Answer

Project feasibility 1 Answer

How can I store game data outside of scripts.(e.g Total list of inventory items) 2 Answers

Unity3D: How to save an array of gameobjects with arrays of position in xml and load them back in correctly? 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