- Home /
Loading image for inventory from calculated path
Hey guys :D
I was working on my inventory system (Everything worked while developing) and everything was fine until I build it. The Sprites for the items were not loaded and this caused quite a lot of errors. My attempt for this was the following design:
Each item was in a certain folder in my "database" (Not a real one, but more like a hierarchy of folders). Each folder than contains:
A .json file with attributes
Various .json files for translations
A model
A sprite for the inventory
This "database" was in the Resources folder first. but when I built the game, It couldn't be loaded. I've then read on Unity that using that Resources folder isn't a good idea. So I moved it to another folder. But since I can't use Resources.Load anymore I have a problem.
Basically I just need a way to dynamically import the required image to the inventory-object.
P.S.: I had the idea that I would structure the folder hierarchy like the ID. For example item with ID 00-00-01 would be in ItemDatabase/00/00/01 and then I could find all my stuff, that I mentioned above. I really really like this concept, because I can easily add more items just with a single folder and I don't want to give it up, unless it's total [insertBadWordHere]
P.P.S.: I assume that the same thing happens with the prefabs for all items. So I probably need a clever solution for this too.
Thank you guys in advance!
Could you elaborate?
"...This "database" was in the Resources folder first. but when I built the game, It couldn't be loaded. I've then read on Unity that using that Resources folder isn't a good idea..."
I had a folder structure for the items (This was my database). This database was in my Resources folder. It looked basically like this: Assets/Resources/ItemDatabase/Items... Everything worked while I was working in Unity. I had functions to load the appropriate Sprite and Prefab into the scene (With Resources.Load()). But after I built the game, the Resources folder changed quite a lot. I no longer had these item paths and the functions for loading sprite and model said that the required files couldn't be found ($$anonymous$$y own error message. It is displayed if I try to load something that doesn't exist). While I was searching for answers, I found this article https://unity3d.com/de/learn/tutorials/topics/best-practices/resources-folder and it clearly says that it shouldn't be used in this case...
I hope you get the idea :)
Your answer
Follow this Question
Related Questions
Resource folder doesn't build. Why is it empty? 1 Answer
Distribute terrain in zones 3 Answers
How To Refresh Resources Folder in Build? 1 Answer
Subfolders with Resources.Load not working 2 Answers
Mouse cursor is giant in Mac builds. 1 Answer