I want to get a list of colliders inside an area on button press, and this looks like a good option.
However, I seem to be unable to find any information on how to use it correctly.
This states I am to provide a Contact Filter and a Collider2d, but as far as I’ve been able it does not seem to want any of the variables I feed it.
Does anyone have an example on OverlapCollider being used? Google, does not apparently, at least not down to page five.
Make sure you’re passing an array that is not empty (of zero size). Basic Arrays cannot be re-sized, hence if you pass an empty array, you’ll get zero results back.
From the docs:
“results - The array to receive results. The size of the array determines the maximum number of results that can be returned.”
Otherwise, are you able to provide code that you’ve tried so far?
EDIT:
A basic example could be something like the below code:
Collider2D myCollider = gameObject.GetComponent<Collider2D>();
int numColliders = 10;
Collider2D[] colliders = new Collider2D[numColliders];
ContactFilter2D contactFilter = new ContactFilter2D();
// Set you filters here according to https://docs.unity3d.com/ScriptReference/ContactFilter2D.html
int colliderCount = myCollider.OverlapCollider(contactFilter, colliders);