How to initialize a script field with a prefab?

When you SELECT a SCRIPT in the Project view, and there is a public GameObject field inside this script, that field is displayed on top of the Inspector view. Then I drag&drop a prefab to that field. But when I try to instantiate that prefab it says it is null.

Note: the script with prefab is not yet added to any object. It is only a script that will be add dynamicaly to GameObjects.

Make sure that your prefab is inside a folder called “Resources” to you instantiate it by code, like that:

GameObject obj = (GameObject)Instantiate(Resources.Load("Prefabs/Your_Prefab_Name"), this.transform.position, Quaternion.identity);