go1=go2; Destroy(go2) and still have go1 != null

Hi,
I suppose its rather general C# scripting question then unity related but still.
I have two classes

public class Item
{
[INDENT]// Icon for inventory (drag'n'dropped in editor from prefab)[/INDENT]
[INDENT]public gameObject icon;[/INDENT]

[INDENT]// When Clicked[/INDENT]
[INDENT]OnInput[/INDENT]
[INDENT]{[/INDENT]
[INDENT][INDENT]inventory.AddItem(gameObject) // In this case everything's OK[/INDENT][/INDENT]
[INDENT][INDENT]Destroy(gameObject)[/INDENT][/INDENT]
[INDENT]}[/INDENT]

}
public class Inventory
{
[INDENT]public GameObject itemToInventory;[/INDENT]
[INDENT]private GameObject grabbedItem;[/INDENT]

[INDENT]OnInput ()[/INDENT]
[INDENT]{[/INDENT]
[INDENT][INDENT]AddItem(grabbedItem); // In this case I'll get an exception [/INDENT][/INDENT]
[INDENT][INDENT]Destroy(grabbedItem);[/INDENT][/INDENT]
[INDENT]}[/INDENT]
[INDENT]public void AddItem (GameObject item)[/INDENT]
[INDENT]{[/INDENT]
[INDENT][INDENT]if (item.GetComponent<Item>() != null)[/INDENT][/INDENT]
[INDENT][INDENT]{[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]itemToInventory = item.GetComponent<Item>().icon; // In this case everything is FINE[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]} else[/INDENT][/INDENT]
[INDENT][INDENT]{[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]itemToInventory = item; // In this case I'll get exception on instantiation[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]}[/INDENT][/INDENT]
[INDENT][INDENT]//StartDelay()// And call CallAfterAnimation() after its over[/INDENT][/INDENT]
[INDENT]}[/INDENT]
[INDENT]OnUpdate[/INDENT]
[INDENT]{[/INDENT]
[INDENT][INDENT]//When delay is over call CallAfterAnimation()[/INDENT][/INDENT]
[INDENT]}[/INDENT]

[INDENT]// Called with delay[/INDENT]
[INDENT]public void CallAfterAnimation[/INDENT]
[INDENT]{[/INDENT]
[INDENT][INDENT]Instantiate(itemToInventory)[/INDENT][/INDENT]
[INDENT]}[/INDENT]

}

So the thing is that when I’m saving temporary item from Item Class (through AddItem() in Inventory)

itemToInventory = item.GetComponent<Item>().icon;

and in the next moment destroying this gameObject Destroy(Item), itemToInventory stays valid (not null) and after delay Instantiate(itemToInventory) works just fine. But when using Inventory’s class own method OnInput to save object like following (again through Inventory’s AddItem() )
itemToInventory = item; then calling Destroy(item) makes itemToInventory == null and after delay there’s nothing to instantiate from so I’m getting exception at final method CallAfterAnimation().
The question is: how to save properly gameObject in itemToInventory variable to keep in not null even after destroying the object from which it got all the data?

I think you are able to keep this data in a temp object, created before destroy your object. Just create a temp object, and write code with static variables, and overwrite this with your data.

Saying g01 = g02 doesn’t make a new object. It’s just two references to the same object. If you destroy the gameObject then both references will be null.

In the working case you say :

itemToInventory = item.GetComponent().icon;

so when you destroy the gameObject “item” the gameObject “icon” is still around.

But documentation says that in my case game obj its components and transform children will be destroyed, how comes that icon survives this impact? And one more q, I have to call go1 = instantiate(go2) in order to make copy that won’t be destroyed on destroy(go2) ?
Thank you