Pretty much title says it all. I’m trying to implement a basic Inventory system where:
Player can pick up items from the scene
Picked up items get stored in the inventory
Selected items can be used and once they are used they are removed from the inventory.
My problem is that I can’t really seem to decide what is the best method. I’ve been searching around and pretty much a lot of posts mention that there aren’t specific ways to do this it really is a matter of how YOU want to achieve it. That being said, I have a new way but let me explain my previous way.
Previous way (didn’t work, couldn’t get it to work properly)
- Idea was to create a list which takes gameObjects of those items and store them in the list. The list acts as the inventory so 15 elements means that there are 15 items in the list. Problem was that each time I picked up the item, I wanted to destroy the item from the scene but I couldn’t achieve this because as I added the gameObject to the list, then destroyed the gameObject from the scene, since the added listItem is referencing gameObject from the script, destroying the script destroys the gameObject from the inventory. Essentially I’m adding a null each time. After much trying, I got no where and ended up doing the same thing in different ways.
New Way (hoping to this)
-
I choose the previous way to start with is because I wanted the picked up Items from the scene to be deleted for the game to be ‘efficient’ in having/managing items in the scene. I realized that I barely have too many items at the moment in my scene so the new way would simply be hiding items using:
GetComponenet.enabled = true/false
I just want to know whether there would be some sort of impact if I just have items in the scene then just hiding them and showing them when the player selects that item from the inventory.
Take The Forest as an example. Built in Unity, has an Inventory system. I’m wondering if the items that the player has are the items that have been moved from Position A (point of origin) to Position B (players inventory space)?
TL;DR - Just want to know whether hiding/showing is better than deleting and recreating objects when it comes to inventory system and picking up etc.