Can't load Prefabs when building Standalone file

I’m currently making an ARPG, part of my script looks like this:

class SkillFireball extends MonoBehaviour{
  var harmful:GameObject; // Drag the prefab of Fireball to this variable
  function AimAndFire(){
      Instantiate(harmful, pos, rot);  //---- Line X -----
  }
}

I know that I only write a small portion of code here, but the strange thing is:

  1. There is no error nor warning in editor mode. And I’m sure I’ve Drag the prefab of Fireball to var harmful in Inspector window.

  2. The Windows executable file I built always occur errors at Line X: “argument exception: the prefab you want to instantiate is null”

After I changed my code to this, the problem solved.

class SkillFireball extends MonoBehaviour{
      private var harmful:GameObject; // Drag the prefab of Fireball to this variable
      function Awake(){
        harmful=Resources.Load("SkillFireballHarmful", GameObject);
      }
      function AimAndFire(){
          Instantiate(harmful, pos, rot);  //---- Line X -----
      }
    }

But using Resources Class is hard for me to maintain, thus I’ve heard that it is less efficient.

Is there any idea why my first code don’t work?

Found the answer!

Sadly, variables assigned in Inspector View won’t be initialized if using AddComponent(). Seems that the compiling rules in editor and standalone are quite different. Hope they’ll fix it soon.