• 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 /
  • Help Room /
avatar image
Question by ButterBridge · Apr 11, 2016 at 08:06 AM · 2ddatabaseinventoryinheritanceitems

How to handle inventory in 2d game, via xml, no game objects (inheritance? interface?)

Hello all,

I have a system w$$anonymous$$ch I have cobbled together off various tutorials and some intuitively hacking stuff together. T$$anonymous$$s is for a 2D rpg, largely UI based game. However I want there to be lot that players can do with items in the game, such as equip, use, repair, upgrade, break up for components, buy/sell etc.

I have an xml database of items w$$anonymous$$ch are constructed from properties in a BaseItem class and put in a BaseItem dictionary, no problem.

Gameplay wise, there is no need for these items to 'exist' in the scene - only that the game knows whether or not the player has them in their playerInventory List, and that there is a sprite for them to appear in the inventory. So the inventory doesn't really contain the items, but just scans the playerInventory and builds itself accordingly. Again, all fine.

However, I can't help but t$$anonymous$$nk I am missing a trick on how to manage the properties of these items. My xml document has lots of fields such as 'ConsumeEffect' and 'EquipBonus' w$$anonymous$$ch clearly don't apply to every item in the game. So I leave these blank.

I know that I could create c$$anonymous$$ld classes of BaseItem, for weapons/consumables etc. but is there any point? Apart from the benefit of streamlining the sprawling xml document into a few more concise ones with fewer variables, and then having a separate dictionary for each, is there any good reason I should do t$$anonymous$$s? (As I write t$$anonymous$$s, I'm t$$anonymous$$nking about functions only wit$$anonymous$$n the class, but struggling to t$$anonymous$$nk of a useful example.)

I've also been reading about inheritance, but t$$anonymous$$s seems to me to be an entirely different model to what I'm proposing, and am I right in t$$anonymous$$nking that it would require Game Objects or scriptable objects? And would that effectively mean creating an object for each item in the game? If so, I definitely don't want to go down that route.

I'd be curious to hear collective thoughts - I imagine there will be differences of opinion, but I want to hear them before I go much further t$$anonymous$$s way.

Comment

People who like this

0 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 Oribow · Apr 11, 2016 at 10:00 AM 0
Share

When you have unused vars in a class, you are wasting memory. Inheritance isn't commonly understand as an Unity thing. It would be the way to go here. Just google c# polymorphism or c# inheritance.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Zelda-like inventory system 0 Answers

Inventory and item class design 0 Answers

Harcoding items vs using a JSON database 0 Answers

SUPER WEIRD BUG: Breakable Drops Multiple Items if Hit by Multiple Bullets 3 Answers

Best way to store a large ammount of spells ? 1 Answer


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