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

Getting null reference exception

Discussion in 'Editor & General Support' started by itachi4365, May 22, 2014.

  1. itachi4365

    itachi4365

    Joined:
    Sep 24, 2012
    Posts:
    40
    Hi,
    I made a game which is divided into two scenes. The first scene consists of menu the second scene consists of the gameplay.
    The gameplay scene consists of a compass script attached to a active gameobject with public reference to other objects of the same scene, like player transform, some other transforms. I populate these references manually in the inspectors.
    The game works perfectly in editor, but when I play it in standalone windows build I get null reference exception. On going through the log I found out that the compass script is throwing the error which is due to it not being able to find the objects mentioned earlier.
    I am not able to figure out why is this happening.

    Please let me know what might be going wrong.
     
    Last edited: May 22, 2014
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    What do you mean with "manually"? In code or in the inspector?
    What do you mean with "texture transform"? A transform of a GUITexture?
     
  3. itachi4365

    itachi4365

    Joined:
    Sep 24, 2012
    Posts:
    40
    By manually I mean in inspector texture transform means the transform of the particular sprite, since I am using NGUI.
    Sorry for not being clear.
     
  4. Warped-Imagination

    Warped-Imagination

    Joined:
    May 18, 2014
    Posts:
    51
    You will sometimes find that objects in the editor will initialize in a different order to when they are played on device or as a standalone.

    My guess is that in one of your Awake or Start functions of a game object or component you are trying to use something on another game object or component that is yet to have started and therefore been initialize. This is where the Awake and Start play there part so you can setup components and properties in Awake and then other game objects can access them in Start.

    Try doing some script debugging and the null should become obvious