Search Unity

NullReferenceException

Discussion in 'Scripting' started by Eikewi, Jan 19, 2020.

  1. Eikewi

    Eikewi

    Joined:
    Jan 19, 2020
    Posts:
    1
    Hey i want to make an 2D Player that can run and jump but it doesnt work.
    it says:
    NullReferenceException: Object reference not set to an instance of an object
    Grounded.Start () (at Assets/Scripts/Grounded.cs:12)
    NullReferenceException: Object reference not set to an instance of an object
    Grounded.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts/Grounded.cs:25)
    NullReferenceException: Object reference not set to an instance of an object
    Grounded.OnCollisionExit2D (UnityEngine.Collision2D collision) (at Assets/Scripts/Grounded.cs:33)

    Can somebody help me? I am a beginner and the programm is from the internet but anyway it doesnt work.
    Thank you for helping!
     
  2. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    224
    Read through the exception, it tells you which file and what line of code caused the problem (Grounded.cs, line 12) so click on that and it'll open up the IDE and take you to that line, it should give a clue as whats wrong. Null reference usually means it expects a reference to something, but either that reference was never set, or the thing was destroyed at some point.