Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: cloudsyk3 on June 03, 2014, 04:21:37 AM

Title: NullReferenceException with GetComponent
Post by: cloudsyk3 on June 03, 2014, 04:21:37 AM
My code is as follows:
  1. gameObject.GetComponent<UISlider>().value = 0.00f;
  2.                 Debug.Log ("loading value = " + gameObject.GetComponent<UISlider>().value);

and console log is:
NullReferenceException: Object reference not set to an instance of an object
loading value = 0

It is strange that it says null ref but could print out, the script is set in the gameobject.

Thanks
Title: Re: NullReferenceException with GetComponent
Post by: Caio.Lib on June 03, 2014, 09:14:10 AM
Hi,

When you click on the message in the console is the same GameObject?
Are you using more than one script for this GameObject?

I think the error comes from another script.