K
K
Kot Kotov2020-05-27 08:03:32
Unity
Kot Kotov, 2020-05-27 08:03:32

How to fix NullReferenceException error?

There is a bullet object on it there is a script with the OnTriggerEnter2D function. The problem is that when creating a bullet next to a wall, it will be destroyed after a collision, but when the bullet hits the wall, we get this error

NullReferenceException: Object reference not set to an instance of an object Bullet.OnTriggerEnter2D (UnityEngine.Collider2D col) (at Assets/Scripts/Bullet.cs:23)

PS On the 23rd line of the code, the curly brace OnTriggerEnter2D opens
5ecdf49fe4db5753910641.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kot Kotov, 2020-05-28
@kot123123

The problem was in this line of codeif(!PV.IsMine) return;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question