Inventory Questions (No code needed)

I’ve been playing around with an inventory system and hit a wall. I have a list which is type item, and class inheritance for types if items. I wanted to store all game objects in the list, but I realized I’ve been destroying them when picking them up, which ruins the reference. I thought maybe they could be hidden, or disabled, but that worried me when I contemplated going to other scenes, because the same objects wouldn’t be there. I know in other languages an object is just pure data. Then you can store, say a php object, in an array, and access it whenever. Unity seems to be a little different.

What should I do here? Can’t I just store the pure class information in the List?

Edit: I just did a test and instantiated a new class, and set all the values from the game object before destroying the object. After storing the newly instantiated class object, that I assumed would be all the values, I’m still getting null reference error.

Unity is not that different, you can store the items as “pure data” and access them anywhere. The problem is, that you’re storing their visual representations (the gameobjects), which are by default destroyed when changing scenes.

You can either keep the objects alive with Unity - Scripting API: Object.DontDestroyOnLoad, or you can store only a data model while letting the gameobject be destroyed. When the item would be needed again, you would recreate its gameobject (from a prefab for example).

EDIT:
Just remember that when you’re using gameobjects and components, they are represented in the scene and can be destroyed during scene changes or by using Unity - Scripting API: Object.DontDestroyOnLoad.

Instances of a plain C#-classes (ones that don’t inherit MonoBehaviour), they will only be disposed by the garbage collector (triggered when you no longer have references to the instance).