Instantiated Prefabs and Null Reference Exceptions?

Hello,

Unity is throwing Null Reference Exceptions at run time. The kicker is that everything seems to be working as intended in terms of game play. What’s going on here? My script is below. Thanks in advance!

Note: this script is attached to a prefab that gets instantiated at run time. The public GameObject references (particle1 -4) are also Prefabs that have been assigned via drag and drop in the editor. The console says my problem is on line 24.

using UnityEngine;
using System.Collections;

public class BallManager : MonoBehaviour
{
    public GameObject explosion;

    public GameObject particle1;
    public GameObject particle2;
    public GameObject particle3;
    public GameObject particle4;

    GameObject _instantiator;



    void Start ()
    {
        _instantiator = GameObject.Find ("Ball_Instantiator");
    }
   
    void OnTriggerStay (Collider controllerCol)
    {
        if (controllerCol.gameObject.GetComponent<InteractionManager> ().triggerDown == true)
        {
            Debug.Log ("Start Fade");
            particle1.GetComponent<Additive_Shader_Fade_Out_Curve> ().enabled = true;
            particle2.GetComponent<Additive_Shader_Fade_Out_Curve> ().enabled = true;
            particle3.GetComponent<Additive_Shader_Fade_Out_Curve> ().enabled = true;
            particle4.GetComponent<Additive_Shader_Fade_Out_Curve> ().enabled = true;
        }
    }

    void OnTriggerEnter (Collider col)
    {
        if (col.gameObject.tag == "Boundary")
        {
            _instantiator.GetComponent<SpawnManager> ().ballDestroyed = true;
            Instantiate (explosion, transform.position, transform.rotation);
            Destroy (this.gameObject);
        }
    }
}

Again, everything executes perfectly at run time, so how could that be if my references were null? Puzzled.

On further inspection it seems that the Null Reference message appears once the Prefab Ball(which contains the script that’s throwing the errors) is parented to another GameObject and then un-parented. Apologies, I know this is a bit convoluted.

Weird. So I fixed it by accessing the Prefab components from another (non Prefab) GameObject with GameObject.Find(“the Prefab”).GetComponenet().enabled = true. Not sure why I couldn’t do this on the Prefab but hey, if it’s not broke? …This is gonna keep me up tonight.