Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Object reference error

Discussion in 'Scripting' started by Grady Lorenzo, Nov 6, 2011.

  1. Grady Lorenzo

    Grady Lorenzo

    Joined:
    Jan 18, 2010
    Posts:
    407
    I have looked over this bit several times and to me, it seems very simple and straightforward.

    Unity thinks otherwise...

    Code (csharp):
    1. var Host : Transform;
    2.  
    3. function Update () {
    4.     if(Host.GetComponent("BracketUI").Winners[4] != ""  Host.GetComponent("BracketUI").Winners[6] != ""){
    5.         if (GetComponent(Flare).color.r < 1){
    6.             GetComponent(Flare).color.r += .01;
    7.         }
    8.     }
    9.     else{
    10.         if(GetComponent(Flare).color.r > 0){
    11.             GetComponent(Flare).color.r -= .01;
    12.         }
    13.     }
    14. }
    For some reason it keeps giving me the "Object reference not set to an instance of an object", a total of 8 errors, one for each object the script is attached to... I really don't see what the problem is....
     
  2. CoreVerse

    CoreVerse

    Joined:
    Nov 6, 2011
    Posts:
    11
    You need to define a variable for each object.
     
  3. Grady Lorenzo

    Grady Lorenzo

    Joined:
    Jan 18, 2010
    Posts:
    407
    I did that. And verified that each name was spelled correctly, and that each script reference is spelled correctly.