Prefabs VS Scriptableobject - or anything better?

Hey guys, I’m not sure if this is the right place for this thread.

I’m working on a gacha style game where each player can potentially have over 1000 items.

Currently I have all the item data stored on a mysql server, and when the player logs in, the database gets downloaded, and based on the item ID, it instantiates a prefab with the same ID.

I have no idea if this is a good idea, tbh, it feels weird to have see so many gameobject in the hierarchy. Like having all your inventory items in the hierarchy and the items are not always being viewed.

If this is normal then I can continue what I’m doing, but it just feels like it’s a bad idea.

I’ve briefly looked into Scriptableobjects and I’m wondering if it would make more sense.

I’m a noob so I’m totally open to learning other methods if I’m going about this the wrong way!

Thanks

What does normal mean? If something works it works. What feels bad?

In what ways might scriptable objects help? They cannot be instantiated in the scene like prefabs. Whatever parts of your items exist as interactable objects and not merely as data cannot exist as scriptable objects.

1 Like

The approach you describe seems mostly reasonable.
If there are no issues, then nothing needs fixing.

Basically, one of the possible appraoches to get something done in unity is “everything you see is a game object” approach (everything you don’t see is also a game object).

Something like a button, for example, could be composed out of several game objects. So having tons of inactive objects is reasonable.

Also google “unity object pooling”.

2 Likes

It depends what your item setup is like. There are 100 ways to do inventory/item systems.

For example, have you separated the ‘item data/definition’ (exists in database only) from the ‘world item’ (exist in scene, instantiated from prefab) or ‘inventory item’, etc? It seems like you haven’t, and have it all rolled into one.

ScriptableObjects are good for storing the item data. It means you can just duplicate and rename one of them to create a new item (more like ‘item definition’), vs building a new prefab, or writing C# code create new instances.

If the GameObject is just there as data then it might be a bad idea, unless you need it there to allow click-dragging into the inspector.

Are your prefabs something that would be visible in the scene, or just pure data? In the latter case, they could just be plain C# classes - no need to serialize them if they’re already being pulled in from a database at runtime.

1 Like

If this is plainly an editor issue that you are “psychologically” frustrated with, try setting the game objects HideFlags to HideInHeirarchy.