Cannot create a 2D collider array

Hi, I’m having an issue where an error comes up saying “Cannot implicitly convert type ‘UnityEngine.Collider2D’ to ‘UnityEngine.Collider2D’”. I’m not sure how to resolve this, but after some reading I’m sure it has something to do with Lists, which is something I’m not familiar with yet (still learning programming).

The effect I’m attempting to create is a blowback effect (like an explosion pushing back entities around it), but only the Y-axis is affected. Haven’t been able to test if the effect works yet, due to this error. Thank you for anyone who’s able to provide advice.

void BlowbackArea(Vector2 location, float blowbackRadius, float hpmMagnitude)
    {
        Collider2D[] objectsInRange = Physics2D.OverlapCircle(transform.position, 6.5f, whatIsHexPlate);
        foreach (Collider2D col in objectsInRange)
        {
            HexPlate hexPlate = col.GetComponent<HexPlate>();
            if (hexPlate != null)
            {
                float proximity = (transform.position.y - hexPlate.transform.position.y);
                float effect = 1 - (proximity / blowbackRadius);
            }
        }
    }

Physics2D.OverlapCircle only returns one Collider2D. That’s why the error. Use OverlapCircleAll, which returns the desired array of Collider2Ds, which is probably what you intended to do

Better still use the non-allocating version OverlapCircleNonAlloc. Note you need to allocate an array that’s large enough for the number of results you expect and pass that.

Thanks @hexagonius and @MelvMay. I should’ve looked into it further ahh D: So simple. Much appreciated.

Wow what a coincidence… It just so happens that I was trying to do the same thing (an explosion affect) but I encountered this error! Thank you for helping me out @hexagonius and @MelvMay :slight_smile: