How to stop enemies from spawning through walls?

In my script, enemies spawn in a circle around the player. The problem is, they tend to spawn into walls. What I tried to do was to detect if they collide with a wall at spawn, and if they do, move them to a spawn point I set up. My Script that detects the collision looks like this:

 void OnCollisionEnter(Collider collider)
    {
        if (collider.gameObject.tag == "wall" && alreadySpawned == false) {
            alreadySpawned = true;
            enemy.MovePosition(spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position);
            Debug.Log("I spawned");
        }
    }

I have no idea why it doesn’t work. Maybe because I use mesh colliders? (I create simple shapes in blender fot the collider, import it to unity and use a mesh collider on it)
Thanks

I solved it by checking in the if statement wheter the distance from the navmesh was smaller than 0.1. Still don’t know why it didn’t work with the colliders though.