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.

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:
    2
    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:
    25,914
  3. Brathnann

    Brathnann

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

    JeffDUnity3D

    Unity Technologies

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