Component references when GameObject destroyed?

Hello! Here’s my situation - I stumble on an item (say) with an Item component attached to it. I indicate the player that pressing ‘e’ will pick it up. He hits ‘e’. In my code, I’ve been waiting for this to happen and so it triggered this function that’ll first fetch the item type and add a reference to the respective item Dictionary. after that is DONE, we no longer need the GameObject and therefore call Destroy() on it.

Now comes the trick part, if I destroy it, the components will be gone with their master (the GameObject), which, I assume, would make those references in the Dictionary hopeless!! That’s the crux.

Now I’ve this strange feeling that there exist this method that disconnects the component from the GameObject (or is it just my crazy mind?).

Can you people please show me the way?

TIA

P.S also, where’s the offline docs? its a download, right?

Could you try separating the GameObject and Item classes? Store the items in a master Dictonary and create a GameObject that has a script that has an int(itemID) that represents the items key in the item dict. When you press ‘e’ callout to the item dictionary using the item itemID stored on the GameObjects script and add a new item created from the item dict to your inventory. Then destroy the gameobject.

If destroying the gameobject is purely for cosmetic reasons, consider disabling its renderer instead.

Create a struct with the relevant variables in it which match what data it is you are trying to record. Make a List of Type YourStruct and store the info you want from that object’s components in it.

Then you can destroy the object.