So i’ve been trying for a while now to figure out a good item system for my game. I thought I found a solution by using GameObjects as items, since it checked all of my requirements:
- The item needs to be visible when equipped (I just position the GameObject to the correct slot)
- The item needs to be an instance, that is, have unique values such as durability and other fields specific to certain items
- It needs to have a pickup with proper colliders. That is, the colliders should match the shape of the item.
- Weapons will have trigger colliders that will define the hitbox of that weapon. For example, a sword would have a box collider covering the entirety of the blade.
- Some items will have unique animations.
- Items will be usable, and even have unique behaviours while equipped. (Such as balloons lowering your gravity)
The way I’m doing it now, is I have a public class Item : MonoBehaviour, IInteractable
attached to a GameObject, where I define the behaviour of the item, and then a public class ItemData : ScriptableObject
where I keep the name, description, stats, etc. This works fine, and allows me to easily make items with unique behaviours, animations etc, since I’m just working with a normal GameObject, and it fulfills every requirement on the list.
But, I don’t like this approach since it creates a lot of problems when handling it in the inventory. Here are a few examples:
- When picking up the item, I need to disable all colliders and rigidbody, and when dropped re-enable them. This just feels very hacky.
- Every slot has two fields: Item and Amount. When I have, let’s say 10 of an Item in a slot, there is really only one instance of that item. But when I need to split it into multiple slots, I need to create a new instance for every slot, and when put back together, I need to destroy any extra instances. Doing this often could lead to performance issues I think.
- Since the item is both the pickup and the item, I can’t have an item pickup that gives you x amount of that item.
- Using prefabs to store items is a bit of a pain
Ideally I’d want to have ItemData scriptable object and Item class to define behaviour. Then have some sort of visual representation of that object in the world. But then I wouldn’t have two of my requirements: Animations, and the colliders.
I’ve searched and searched but I can’t find anything that suits my needs, which leads me to believe maybe I should rethink what my necessities should be. But I still wouldn’t really know what the best way of doing an inventory system would be.
Can someone smarter/with more experience than me guide me a bit on what I should be doing? Should I keep using GameObjects as items, should I use normal classes? Or should I rethink everything?