Load Sprite and Prefab without Resources.Load

Hey guys!

I’m struggling a lot with my inventory system. I tried to optimize it when I found this article:

What I want to do is simply load a sprite and a prefab for my items into the scene. Here is an overview how I designed my item database:

Each item has a specific folder. Inside there is a .json file which contains the properties of this item. As well as a Sprite (for the inventory) and a prefab for the instantiation.

If you have a better idea for a database instead of folders, please present it here ;). I’d highly appreciate it!

But I don’t want to have a plain array database*, since I want to implement quite a lot of items. Furthermore different item types have different properties, so only one database wouldn’t be enough…

*By plain array database I mean something like:
public Items itemDatabase;

Thanks in advance :smiley:

Well, if you don’t want to set up references before runtime, you’ll need to use the resources folder.

What I’ve done in the past is:

Set up a database script that can be used as a prefab. Store the data however it makes the most sense for you.

Write an editor script that allows the items to be dropped into a field that adds it properly to the database.

Use Unity’s custom serialization to bake that complex dataset down to a simple array for saving to the disk. When you deserialize it on load, take the array you get and filter it out to your complex dataset.

An alternate way would be to use resources, and have a simple text file asset that lists all the prefabs to load. Then you can Resources.Load each one at load-time and put them into the appropriate place in your database.

Thank you guys :smiley: I highly appreciate your answers. I think I’ll go with the new ‘plain array’ kind of thing. If I split it into smaller pieces it is indeed a good solution. If I find another alternative I will update this topic.