Cannot make physics.spherecast ignore object.

Turret use spherecast to detect enemy and fire.
The problem is after firing shell, spherecast will return shell as hit object, i need spherecast to ignore the shell.

In the editor, project setting, physics, ignore raycast and shell is unticked , but it does’t work.

I tried this and that for few hrs, but still cannot solve it.

    void Fire()
        RaycastHit hit;

        if (Physics.SphereCast(barrel.position, shellRadius, direction, out hit, attackRange))    

            if(nextFire < Time.time && hit.transform.gameObject.layer ==enemyLayer)
                    nextFire = Time.time + fireRate;     
                    GameObject shell = Instantiate(Resources.Load("RailGunShell"), barrel.position, barrel.rotation) as GameObject;

                    shell.GetComponent<Rigidbody>().AddForce(direction * shellSpeed);


The physics layer settings are for collisions only. To be ignored in normal raycasts you can either put your object into the IgnoreRaycast layer, or in your case: Use a signature of the raycast method that includes a layermask parameter:

int SHELL_LAYER = 12; // your layer index here
int layerMask = ~(1 << SHELL_LAYER);
if (Physics.SphereCast(barrel.position, shellRadius, direction, out hit, attackRange, layerMask))