GameObject not null before Instantiate

Hi all,
I have a problem with Initiate function:
I declare a GameObject as a public variable in my C# script:
public GameObject myGameObject;
Then in editor I drag my prefab into my C# script position.
I debug I recognize that before I call Instantiate(myGameObject), myGameObject has existed ( not null), Why???

When you create the variable GameOBject myGameObject and pass it a prefab, you are giving it a value, therefore it is not null.

What Instantiate does is to create a copy of the object you pass as a parameter, not to store a GameObject into that variable.

As an example:

public GameObject myGameObject;

void Start()
{
    Instantiate(myGameObject);
}

This will create a copy of whatever GameObject (from the scene or a prefab) you have dragged to myGameObject variable, but you will have no reference to it. If you want to keep a reference for the new copy you can do it like this:

public GameObject myGameObject;
private GameObject copyOfGameObject;

void Start()
{
    copyOfGameObject = Instantiate(myGameObject) as GameObject;
}