Potential bug in unity or am I misunderstanding something?

I am trying to build buttons to use in a main menu screen, I made a script and an object structure that should work for any buttons of this design. The first button I tested it on worked fine, but when I attached the script to another button (part of a dialogue box, hence different canvas) unity told me that there was a NullPointerException. In typical fashion, it didn’t tell me anything specific but it at least told me that the problem was on line 11 of the script. The only problem is that, upon entering playmode, the script still works until that point (and even the line causing the error performs its task). The original button implementation also still works, the only thing that is broken about the new one is that the functions “OnMouseOver” and “OnMouseExit” don’t get called.

Also trying to open the script from the error-producing gameObject causes MonoDevelop to tell me the same NullPointerException.

Image explanation of the problem.
alt text

Also, I just removed the working script component from the working gameObject and reapplied it, that caused it to break as well.

The script’s contents is below:

public class Menu_Button_Hover : MonoBehaviour {

private GameObject selected_overlay;

void Start () {
	var parent = transform.parent.gameObject;
	selected_overlay = GameObject.Find(transform.parent.gameObject.name + "/Outline");
	selected_overlay.SetActive(false);
}

public void OnMouseEnter(){
	print ("ExitOver");

	print (selected_overlay);
	selected_overlay.SetActive(true);
}

public void OnMouseExit(){
	selected_overlay.SetActive (false);
}

}

I’m at a loss here. Any input is greatly appreciated!

I solved the problem, it turns out that there was a problem with the script I was using. I copied the text from the script, put it into a new script and attached that to the relevant buttons. This solved the pointer issue.

The reason the button which wasn’t working didn’t work was because the text gameObject had “Raycast target” turned on.