L
L
LeBrone2021-12-03 11:35:56
C++ / C#
LeBrone, 2021-12-03 11:35:56

How to fix this error NullReferenceException: Object reference not set to an instance of an object Damage.OnTriggerEnter2D?

I made a collider for melee range. When another object enters this collider, Unity throws an error
Script:

void AttackPoint()
    {
        Collider2D[] hit = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
    }

    private void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
            return;

        Gizmos.DrawWireSphere(attackPoint.position, attackRange);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-12-03
@LeBrone

Make checks everywherenull

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question