Hello
So i created a collider script for my 2D project but whenever i play it just spills out “Value cannot be null” error
from boxCollider.OverlapCollider(filter, hits);
this line. In addition for some reason my character isn’t colliding with anything that isn’t in the User Layer “Walls” exclusively.
[RequireComponent(typeof(BoxCollider2D))]
public class Collidable : MonoBehaviour
{
public ContactFilter2D filter;
private BoxCollider2D boxCollider;
private Collider2D[] hits = new Collider2D[10];
protected virtual void Start()
{
boxCollider = GetComponent<BoxCollider2D>();
}
protected virtual void Update()
{
boxCollider.OverlapCollider(filter, hits);
for (int i = 0; i < hits.Length; i++)
{
if (hits[i] == null)
continue;
OnCollide(hits[i]);
hits[i] = null;
}
}
protected virtual void OnCollide(Collider2D coll)
{
Debug.Log(coll.name);
}
}
Any help is appriciated, thanks in advance