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

Question How do I fix this

Discussion in 'Editor & General Support' started by aohlstenius, Nov 13, 2021.

  1. aohlstenius

    aohlstenius

    Joined:
    Nov 13, 2021
    Posts:
    6
    I was following a tutorial as I've never done a 2D project before and trying to make a collision detect script but I keep getting this error

    NullReferenceException: Object reference not set to an instance of an object

    I don't know why and I've done the exact same as the tutorial. If anyone has any ideas I would appreciate it.
    Heres my code
    upload_2021-11-13_9-3-26.png
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    What is the line number? The entire error message? First guess: do you actually have BoxCollider2D on your Player game object?
    Also please do not post screenshot of code, post the code itself in CODE tags.
    screenshot.png
     
    aohlstenius likes this.
  3. aohlstenius

    aohlstenius

    Joined:
    Nov 13, 2021
    Posts:
    6
    I do have Boxcollider 2D and here is the full error message

    NullReferenceException: Object reference not set to an instance of an object
    Player.FixedUpdate () (at Assets/Scripts/Player.cs:32)

    I have no idea which thing on the line is incorrect.
    Also thanks I will make sure to use the code tag next time
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    Your
    boxCollider
    is null, you misspelled
    Start
    .
     
    aohlstenius likes this.
  5. aohlstenius

    aohlstenius

    Joined:
    Nov 13, 2021
    Posts:
    6
    where did I misspell start

    edit do I need a capital letter

    edit edit I used a capital letter and it still has the same error
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,991
    aohlstenius likes this.
  7. aohlstenius

    aohlstenius

    Joined:
    Nov 13, 2021
    Posts:
    6
    thanks i managed to fix it