- Home /
Storing Inventory Item Properties
Hi everyone,
I'm working on creating an inventory system right now for my RPG game, and currently I'm having some trouble wrapping my head around the best way to set it up.
I have a bunch of properties that need to be stored within each item (Name, Icon, Model, EquipArea, etc.).
My main questions are how to write this out so:
I can store each item in an inventory grid slot (I already have the grid setup so that it can show an icon of my choosing in each slot).
I can expand upon it for each item I create.
Thanks in advance!
Answer by sparkzbarca · Nov 08, 2012 at 02:51 AM
your wanting to create a generic item class.
A class is basically a custom type.
Integers are a class. they contain a number and that number can have functions like addition and subtraction and stuff done to it.
You want to create an item class that represents a general item.
You then want to create an inventory class, an inventory class should MAINLY be an array of items (which are made through the item class declaration) and then how things are added and removed from the inventory.
Answer by FakeBerenger · Nov 08, 2012 at 03:30 AM
You need you're objects to be able to switch between those states :
They are physically in the scene, with a mesh, renderer, collider etc. Like a sword on the ground.
They are in the bag and not visible anymore.
They contain informations like name, description, icon, price etc. The player is carrying them, so they are visible and parented to a bone, without a collider.
When you pick them up, you can either deactivate them and parent them to the player, or destroy them entirely. But then, you must be able to reinstantiate them later.
Anyway, there isn't a best way to do an inventory. I suggest you take a look at the corresponding tag here.
Your answer
Follow this Question
Related Questions
Binding Key to first item in array 0 Answers
Can't Assign Item In Array 1 Answer
Setting up an array of Items 1 Answer
How can I store game data outside of scripts.(e.g Total list of inventory items) 2 Answers
How to determine what type of class is being interated through in an array of multiple classes 1 Answer