GameObjects in Resources/Item Objects doesn't get found [SOLVED]

Hey guys.

I have a problem with loading Prefabs as Item Objects for my items.
My Item Class is:

When the game starts, the item icons are correctly loaded from the Resources folder, but the Item Object variable is null, I guess that is because it somehow can’t find the item, or I’m trying to load them in a wrong way.

Can anyone point me in the direction I need to go? :slight_smile:

EDIT: Also, when I manually place the prefab in the Item Object variable when the game i started up and open my inventory, I get a warning saying “Null Texture passed to GUI.DrawTexture”. I find this curious, as this warning only started showing up after I started playing with loading GameObjects from the Resources folder.

Bump

Try using the non-generic version of the Resources.Load and see if that works.

itemObject = Resources.Load("Item Objects/"+ ItemName) as GameObject;

Probably should have said that I have already tried that :frowning: Doesn’t work.
Also tried

(GameObject)itemObject = Resources.LoadAssetAtPath("Resources/Item Objects/"+ ItemName) as GameObject;

Didn’t work either. :S

itemObject = Instantiate(Resources.Load("Item Objects" + ItemName, typeof(GameObject))) as GameObject;

As far as I can tell, I can’t use Instantiate in the Item Class without putting it in either a e.g. the Start method? :S
The Item Class doesn’t inherit from MonoBehaviour. Could be that.

EDIT: The reason I can’t use Instantiate is because the Item Class does not inherit from MonoBehaviour… Anyway to work around that? Or is there another solution?

GameObject.Instantiate

Well, I CAN put the line as:

itemObject = GameObject.Instantiate(Resources.Load("Item Objects/" + ItemName, typeof(GameObject))) as GameObject;

However, it still doesn’t work :S

EDIT: Seems like the problem is that when I create the Item Database, which the inventory receives items from, the item database also doesn’t contain anything in the variable for the Item Object. If I manually put the correct 3D objects into the slots for the Item Objects in the database, the whole thing works as it should. Obviously, I’d like it to happen automatically.

I managed to solve the issue. I did some tweaking here and there, eventually the issue happened in the Item Database. I created a for-loop in the Awake method in the Item Database, which adds the corresponding 3D Object to every item’s Object slot.

Thanks for your help @DonLoquacious :slight_smile: