Object Reference Not Set As Instance error from ngui code

hey all, not sure if many of you use ngui but il ask anyway. im using unity with the free version of ngui and im still quite new to it. my code gives this console error:

“NullReferenceException: Object reference not set to an instance of an object
NGUITools.SetActive (UnityEngine.GameObject go, Boolean state) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:613)
CharacterControler.UseInventory () (at Assets/Script/CharacterControler.cs:288)
CharacterControler.Update () (at Assets/Script/CharacterControler.cs:51)”

is this a ngui issue or has my code gone wrong? my code is here if you need it:

void Update () {
if(Input.GetButtonDown("Inventory") && canInventory){
			canInventory = false;
	void UseInventory(){
		GameObject HudPanel = GameObject.Find("HudPanel");
		GameObject InventoryPanel = GameObject.Find("InventoryPanel");
			Screen.lockCursor = false;
			inInventory = true;
		else if (inInventory){
			Debug.Log("not inInventory");
			Screen.lockCursor = true;
			inInventory = false;
	public IEnumerator InvTimer(float delay){
		yield return new WaitForSeconds(delay);
		canInventory = true;

Yes, you’re actually pretty close. I should have spotted this first time round, but GameObject.Find() won’t work on an inactive GameObject.

Try finding the object on Awake and holding a reference, or set a public reference via the inspector. It’ll be more efficient than calling GameObject.Find() at game time as well :slight_smile: