How to solve conflicting OnValidate() functions

I have two OnValidate() functions in two scripts, one attached to the Enemy (EnemyScript) game object and the other to the Enemies(EnemiesScript) game object.

In OnValidate() in EnemyScript I have the following:

void PrepareEnemyType(EnemyType enType) {

    // by default hasHibernated = false
    if (!hasHibernated) {
        if (enType == EnemyType.Green) {
            gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Sprites/greenEnemy");

        }
        else if (enType == EnemyType.Red) {
            gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Sprites/redEnemy");

        }
    }

    else if (hasHibernated) {
            gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load<Sprite> ("Sprites/greyEnemy");

    }
}

In OnValidate() in EnemiesScript I have the following:

for (int i = 0; i < enemies.Length; i++) {
        if (!enemies [i]. hasHibernated) {
            enemies[i]. hasHibernated = true;

        }
    }

Based on the above, all the enemies should change sprite to greyEnemy sprite, but that doesn’t happen. Before I run the application all of them change to greyEnemy sprite initially, then after I run the application some of them change back to their original sprites, and when I stop running the application they sprites remain the same as when the application was running (different sprites). At this point, the only time that they all become grey again is when I make some other edit to either one of the scripts and save it. Then the above transition repeats. I suspect there could be some conflict with the two OnValidate() functions, not certain though. How can I resolve this?

Put a Debug.Log(gameObject.name + " is running OnValidate", this) in each. You’ll be able to see when each object is running it. My suspicion is that OnValidate is running less often than you think it is.