title: Unity object reference + serialized field. What am I missing?
body: <p>I have a ui Button called "Attack Button". I have a script called HeroBattleController attached to my Gameobject. I have an attack button set as a serialized field and the attack button object dropped on the script in the editor.</p>
  
  <pre><code>[SerializeField]
  private Button AttackButton;
  
  public void SetButtonStatus(bool status) {
      AttackButton.interactable=status;
  }
  </code></pre>
  
  <p>Trying to access that gives me the error NullReferenceException: Object reference not set to an instance of an object</p>
  
  <p>I thought putting the object in the editor would allow me to access it without having to "Find" the object. Can anyone point me in the right direction?</p>
  
  <p><a href="https://i.stack.imgur.com/luETP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/luETP.png" alt="enter image description here"></a></p>
  
  <p>The error is on the line</p>
  
  <pre><code>AttackButton.interactable=status;
  </code></pre>
  
  <p>Complete HeroBattleController script</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  
  public class HeroBattleController: MonoBehaviour {
  
      public static string SelectedHero;
  
      [SerializeField]
      private Button AttackButton;
  
      public void SetButtonStatus(bool status) {
          AttackButton.interactable=status;
  
      }
  
      public void HeroTouch() {
          Debug.Log("Hero was touched: "+this.name);
  
          SetButtonStatus(false);
      }
  
      // Use this for initialization
      void Start() {
  
      }
  
      // Update is called once per frame
      void Update() {
  
      }
  }
  </code></pre>
  
  <p>HeroTouch is called via onClick from the heroprefab object.</p>
  
  <p>Update: I had the herobattlecontroller script attached to two objects, the gameobject at the root of the scene and the heroprefab object. I removed it from the gameobject and only have it on the prefab. However now when I drag the attack button to the script section on the prefab it stays bold and when I run the game the attack button reference is gone. I can drag the button to the running object and it functions as I expected.  I'm clearly missing something on the connection between the object hierarchy and where the objects are usable. Putting the hero battle controller script on the root gameobject only acts the same way meaning it's bold and when ran it's missing the link.</p>
  
  <p>hierarchy during edit</p>
  
  <p><a href="https://i.stack.imgur.com/GjLfN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GjLfN.png" alt="enter image description here"></a></p>
  
  <p>hierarchy during runtime</p>
  
  <p><a href="https://i.stack.imgur.com/jQSLU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jQSLU.png" alt="enter image description here"></a></p>