Class members inside of OnTriggerEnter function?

I cant figure out why I am not able to use my quest class inside my collision function…

The problematic line is commented out inside the OnTriggerEnter.

I have created a couple test variables and they work correctly, but whenever using the members of the quest class it gives me a reference error… maybe I am overlooking something very simple? or does OnTriggerEnter have access problems ?

I would really like to use the custom class (quest) in order to properly organize, any advice would be greatly appreciated.

using UnityEngine;
using System.Collections;

public class npc_questgiver : MonoBehaviour {
	public class quest
		public int unique_ID;
		public string title;
		public string description;

	public GameObject my_player;
	public GUI_HUD my_player_gui_hud;

	public quest my_quest;

	// simple test
	public string test;
	public string testtwo;

	// Use this for initialization
	void Awake () {
		my_player = GameObject.Find ("Player");
		my_player_gui_hud = my_player.GetComponent<GUI_HUD> ();

		// quest data
		my_quest = new quest();
		my_quest.unique_ID = 1;
		my_quest.title = "Introduction";
		my_quest.description = "Hello, Welcome. I am the town healer. Please visit me whenever you feel weary. My services are free... for now.. ha ha ha haha";

		// simple test
		test = "test title";
		testtwo = "test description... so long.. blah blah...";
	void OnTriggerEnter(Collider hit)
		if (hit.gameObject.tag == "Player") 
			//my_player_gui_hud.npc_interact(my_quest.title, my_quest.description);
			my_player_gui_hud.npc_interact(test, testtwo);

I ran your code (with the my_quest bit uncommented) in an empty test scene and it worked. I seems you have not set something else up correctly or something else modifies your values. Does it find the “Player” object and the attached GUI_HUD component correctly?

In this line of code:

my_player_gui_hud.npc_interact(my_quest.title, my_quest.description);

There’s two things that could possibly cause a nullpointer. The first one is if my_quest is null - which is unlikely, as it’s generated in Awake.

The other thing is if my_player_gui_hud (why not just gui_hud?) is null. This is more likely - you’re grabbing it in Awake, but the GetComponent call might return null.

Are you sure that the GUI_HUD component is on the same object as the player in the scene? If the hud is on a child object, you need to use GetComponentInChildren. That’s the most likely culprit.

Finally, it’s not that hard to check what’s throwing the nullreferences - just throw in this on top of OnTriggerEnter:

Debug.Log("gui: " + my_player_gui_hud);
Debug.Log("my quest: " + my_quest);

And you’ll see which one prints nothing after the ‘:’