Search Unity

Bug NullReferenceException: Object reference not set to an instance of an object Enemy.OnTriggerEnter2D

Discussion in 'Scripting' started by Fogusss, Apr 18, 2022.

  1. Fogusss

    Fogusss

    Joined:
    Apr 18, 2022
    Posts:
    7
    I keep getting this error:
    NullReferenceException: Object reference not set to an instance of an object
    Enemy.OnTriggerEnter2D (UnityEngine.Collider2D other
    Because of line 41. Does anyone have a fix?

    upload_2022-4-18_16-20-3.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,739
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Your fix might be as simple as a mistype capital letter. When it comes to Unity special methods, caps matter.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Another hint. All your "void" methods except one start with a capital letter. One is not like the others, and should be