Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Object Referance not set to an instance of an object?

Discussion in 'Scripting' started by Raelin_, Jul 17, 2014.

  1. Raelin_

    Raelin_

    Joined:
    Jul 16, 2014
    Posts:
    20
    Code (JavaScript):
    1. public var target3 : GameObject;
    2. function OnGUI () {
    3.  
    4.     GUI.Box (Rect (10,10,100,90), "Loader Menu");
    5.  
    6.     if (GUI.Button (Rect (20,40,80,20), "camera1")) {
    7.  
    8.             target3  = GameObject.Find("target3");
    9.     target3.animation.Stop();
    10.     }
    the target 3 is a Gameobject in my scene which is a child of another gameobject, the problem i am having is that whenever i go to access the target3(through script) it removes itself from the inspector(I.E, it says Non (Game Object)

    any idea how to fix this?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    line 8 must be returning a null value and is overwriting the value set in the inspector when the script is running.

    check spelling, case, etc. on that argument against the actual target3 object in your scene (and check there is actually an object called target3 in the scene :p)
     
  3. Raelin_

    Raelin_

    Joined:
    Jul 16, 2014
    Posts:
    20
    Thanks :D Worked Great