Author Topic: NullReferenceException with GetComponent  (Read 2970 times)

cloudsyk3

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
NullReferenceException with GetComponent
« 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

Caio.Lib

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 26
    • View Profile
Re: NullReferenceException with GetComponent
« Reply #1 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.