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

NullRefernceException

Discussion in 'Scripting' started by Maxinator5400, Feb 24, 2016.

  1. Maxinator5400

    Maxinator5400

    Joined:
    Feb 22, 2016
    Posts:
    5
    Hello guys, this is my error Code
    NullReferenceException: Object reference not set to an instance of an object
    Mob.attack () (at Assets/Mob.cs:58)
    Mob.Update () (at Assets/Mob.cs:41)

    The Script where the error code comes from:

    Unbenannt.PNG
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Maxinator5400

    Maxinator5400

    Joined:
    Feb 22, 2016
    Posts:
    5
    Hey leftyrighty,

    yes i think so too! but i dont know where the problem is :

    Unbenannt1.PNG
     
  4. Maxinator5400

    Maxinator5400

    Joined:
    Feb 22, 2016
    Posts:
    5
    Can it actually be that it has something to do with the player variable? in Unity i named my character "Player" and not player
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    ok, capitalisation is important in unity.

    Start not start
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    the word "player" in your script is referring to the Transform reference you set at the top, not the name of the gameobject in the scene (which would be player.name) these are two very difference concepts.
     
  7. Maxinator5400

    Maxinator5400

    Joined:
    Feb 22, 2016
    Posts:
    5
    Oh wow, i would have never ever found that!

    Thanks!
     
  8. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    I'd recommend putting the time into learning the naming conventions (as linked above) and perhaps some of the basic tutorials in the learn section. Getting used to the "normal" way of writing code will hopefully let you spot these things in the future and hopefully avoid them in the first place.
     
  9. Maxinator5400

    Maxinator5400

    Joined:
    Feb 22, 2016
    Posts:
    5
    with learning the naming conventions you mean the coding standards?