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. Dismiss Notice

Can you help me with this error

Discussion in '2D' started by milda120, Jun 12, 2021.

  1. milda120

    milda120

    Joined:
    Dec 19, 2020
    Posts:
    9
    upload_2021-6-12_17-47-27.png This is the error this is the script upload_2021-6-12_17-49-32.png if u know how to fix it comment this thx
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    Have you debugged it to see what is NULL on that line? It'd be quicker than asking on the forums. On that line only "target" can be NULL (no reference). This means line 18 isn't finding anything.
     
  3. milda120

    milda120

    Joined:
    Dec 19, 2020
    Posts:
    9
    It dont work
     
  4. milda120

    milda120

    Joined:
    Dec 19, 2020
    Posts:
    9
    upload_2021-6-12_18-48-4.png
     
  5. milda120

    milda120

    Joined:
    Dec 19, 2020
    Posts:
    9
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    What does that mean?

    I see you changed some code but that's got nothing to do with the line where the error is at.
     
  7. milda120

    milda120

    Joined:
    Dec 19, 2020
    Posts:
    9
    So where i need to put the null ??
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    You're not following at all.

    Did you write this code and understand it or did you just copy it from somewhere?

    As I said above, line 18 isn't finding the Player so it's returning NULL which is assigned to "target". I cannot tell you why it cannot find that, only you can see that in your project.
     
    Johan_Liebert123 likes this.
  9. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    Let's break the error down. Object reference not set to an instance. One of the most common errors ever, Key notes are
    - Unassigned reference
    - Object is null
    - Missing reference exception

    In your code, on line 18, your defining what target is. But the problem is it doesn't know what 'Player' is, and when It can't find something it returns as NULL, as MelvMay said. Do you have a script called 'Player'. If not that's probably the case.

    For future reference, posting a pic of code snippets are pointless. Always paste the code here, using code tags especially