Search Unity

Null Reference Error

Discussion in 'Scripting' started by Jsmucker, Nov 20, 2014.

  1. Jsmucker

    Jsmucker

    Joined:
    Sep 5, 2014
    Posts:
    48
    For some reason I keep getting the Null Reference error for this line of code:

    Code (CSharp):
    1. voidOnTriggerEnter(Colliderother)
    2. {
    3. if (animation ["attck1"].enabled == true) {
    4. SendMessage ("Damage", 1.0f, SendMessageOptions.DontRequireReceiver);
    5. }
    6. }
     
  2. Deleted User

    Deleted User

    Guest

    That's not a line that's a block.
    1. voidOnTriggerEnter(Colliderother) - spaces
     
    Last edited by a moderator: Nov 20, 2014
    Jessy likes this.
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    You spelled attack wrong.

    "==true" isn't needed.
     
  4. Jsmucker

    Jsmucker

    Joined:
    Sep 5, 2014
    Posts:
    48
    Copy pasting must have messed up with spaces. attck is the name of the animation. Thanks for the replies, I don't understand what you mean by arrays take integers not strings.
     
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Deleted User likes this.
  6. Jsmucker

    Jsmucker

    Joined:
    Sep 5, 2014
    Posts:
    48
    So how would I fix that?
     
  7. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    "animation" might be null
    There might be no animation clip named "attck1" in the animation component

    Doing some logging/debugging of those things should tell you what's going on.