OnTriggerExit triggers randomly while still in trigger zone

I have 2 game objects a player and an enemy. The player has a rigidbody and an AttackRange named collider set as trigger assigned to it as a child object and it has a script that detects enemies in range then puts them in a List, if you move out of range it removes it. The enemy has a collider as well set as a trigger. Now my problem is that even though the enemy is in the AttackRange it randomly removes it from the lost for no apparent reason, I’ve already wasted 2 afternoons on this looking for answers to my problem, but to no avail.

Here is the AttackRange script.

using UnityEngine;
using System.Collections.Generic;

public class AttackRange : MonoBehaviour {

	public List<GameObject> enemiesInRange = new List<GameObject>();
	float timer;
	
	// Update is called once per frame
	void Update () {
		timer += Time.deltaTime;
	
	}

	public void OnTriggerEnter(Collider other){
		if (other.gameObject.tag == "Enemy" && other.isTrigger == true) {
			if(enemiesInRange.Contains(other.gameObject)){

			} else {
				enemiesInRange.Add(other.gameObject);
				print ("Added: " + other.gameObject + " at " + timer);
			}

		}


	}

	public void OnTriggerExit(Collider other){
		if (other.gameObject.tag == "Enemy" && other.isTrigger == true) {
			if(enemiesInRange.Contains(other.gameObject)){
				enemiesInRange.Remove(other.gameObject);
				print ("Removed: " + other.gameObject + " at " + timer);
				timer = 0.0f;
			} else {

			}
		}
		
	}

	public List<GameObject> getEnemiesInRange(){
		return enemiesInRange;

	}
}

Found this thread and I believe I have a similar problem. My solution is to change the Rigidbody setting ‘Collision detection’ from Discrete to Continuous which fixed it.

My problem was that the enemy would set the trigger just the once and then after 5 seconds or so it would start spamming the trigger each frame as it sat within the collider.

In lot of case problem with collision come with the type of collision you are using (Static Collider, Kinematic Rigidbody Trigger Collider, etc.)
This talk about compatibility with each ones : Unity - Manual: Introduction to collision

For your specific issue, for example, when using a Kinematic Rigidbody Trigger Collider on one GameObject, the other one could be a Static Collider (the GameObject should not have a Rigidbody) and the problem of random exit when still inside the wanted collider will disapear.

Hope it help some people.