Unity getting an object to pass through another object but still trigger collision

basicaly i need an object to be able to pass through an object just like as if it was a trigger, but still detect it as a colision becouse of the way i made hitting enemies work (or a way to get physics2d.overlapboxall to detect triggers), here is the code for my weapon attack and the enemy i need to pass through the player but also do damage to the player.
if (AttackDelay <= 0) { //attacking Collider2D[] EnemiesToDmg = Physics2D.OverlapBoxAll(AttackPos.position,new Vector2(AttackRangeX,AttackRangeY),0, WhatIsEnemy); for (int i = 0; i < EnemiesToDmg.Length; i++) {EnemiesToDmg*.GetComponent<Health>().takeDamage(AttackDamage);}* **
and for the enemy
void FixedUpdate()
{

RotateAndMove(target2);
if (AttackRecharge<=AttackRechargeMax)
{
AttackRecharge += Time.deltaTime;
}

}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.layer==10)
{
player.gameObject.GetComponent().takeDamage(20);
}
if(collision.gameObject.transform==target2)
{

if (!IsVisible)
{
target2.position = player.position + (player.position - transform.position) / 5;
}
else
{
TeleportToCamera(target2);
}
}

}

What’s wrong with OnTriggerEnter2D, should work just fine…