Unturned 4.0 features the ability to store items in items. You can have a container in your inventory, but that container has its own sub-inventory.
How do games pull this off?
Unturned 4.0 features the ability to store items in items. You can have a container in your inventory, but that container has its own sub-inventory.
How do games pull this off?
Make inventories its own data type, allow inventory slots to store the objects you want which could include other inventories.
A lot of games do this, these extra inventories are like “bags” which can hold a limited amount of items.
Now for the programming side of it is too complicated to explain, you should watch some tutorials that teach how to program working inventory systems.
Easy. Look, you should have game object with container script on it to represent the inventory in your game. And you should have some game objects with item script on them to represent items in your game. Now create a new game object, add both item and container scripts and name it “Bag”. Done.
any tutorials / documentation you know of that I can refer to?
Check out this package and it’s documentation
https://docs.unity3d.com/Packages/com.unity.game.foundation@0.3/manual/index.html
Nope, but what palex suggested is a good start.
Although he is asking a question, he has an inventory setup. Probably the main part is getting the items not mixing up with your main inventory when picking or getting items. I think you will just need to use another if statement for that part.
What if my Item is not a MonoBehaviour?
In my implimentation my class Inventory (which is MonoBehaviour) holds an array of ItemStack instances, where ItemStack is a struct that represents the current state of a item stack (ItemType, name, currentStackSize…)
if i want to include an Inventory in the ItemStack struct it wont work because the inventory is monobehaviour so cant exist outside of a gameobject in the scene.
Do you know of any elegant solution to this?
If my items were gameobjects (if i made ItemStack a MonoBehaviour class), what would they be mostly - the item pickup in the scene, or the icon in my inventory screen?
maybe items are attached to ItemPickup gameobjects, and when i pick them up, instead of removing it i just disable it until it is dropped out of the inventory.
I know this thread is 3 years old but i hope someone can help.
Don’t conflate the storage of state (eg, what you have in the inventory) with how you present it within Unity.
Perhaps something in this checklist can help you reason about your design decisions:
These things (inventory, shop systems, character customization, crafting, etc) are fairly tricky hairy beasts, definitely deep in advanced coding territory.
They contain elements of:
Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:
Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.
Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.
Breaking down a large problem such as inventory:
If you want to see most of the steps involved, make a “micro inventory” in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).
Everything you learn doing that “micro inventory” of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.