Enemy AI movement problem

I have been trying to understand this for a long while now, and still haven’t come to a conclusion.
I have an enemy AI working with two colliders (aggroRange and attackRange) that set two bools which indicate if the player is in either of the ranges. The two colliders are placed in two separate gameObjects which are both children of the enemy gameObject (where the enemy AI script is placed). The bools _playerIsInAggroRange and _playerIsInAttackRange are set to true on OnTriggerEnter and to false on OnTriggerExit by two separate scripts placed in each collider.

Here is a code map showing the connection between the bools and the functions:

51707-kjhkhkh.png

The AI is pretty straight forward:

        //If player is within aggro range, but not attack range
        if (_playerInAggroRange)
        {
            if (_playerInAttackRange)
            {
                if (_moving) stopMoveAnimation();
                if (_attackFrequency <= 0 && !_moving)
                {
                    startAttackAnimation();                //Attack
                    _attackFrequency = AttackRechargeTime; //Reset Timer
                }
            }
            else
            {
                moveTowardsPlayer();
            }
        }
        else
        {
            moveToSpawn();
        }
/*This is inside the Update() method of the AI script, which controls everything about the enemy (movement, combat etc.)*/

An example of what the OnTriggerEnter/Exit functions do:

void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("Player got inside attack");
            EnemyScript.PlayerIsInAttackRange(true);
        }
    }

For some reasons, the last else (that leads to moveToSpawn()) is called every frame, even if the first condition (_playerIsInAggroRange) is true. In fact, when I tried to debug the bool variables, they appeared to be true and false in the same frame.
The only functions that write the bools are called by the OnTriggerExit/Enter functions in the aggroRange and attackRange collider gameObjects, and they are called properly (tested with debug.log), so I don’t see how this is happening!

Please tell me if you need any other info to help me fix this problem, any help would be greatly appreciated!

"Do you have multiple parasites cause if so the

getting true and false could just be because one is calling move to spawn and the other isn’t.

the other possibility is your move towards player script is wonky and moving the parasite in the opposite direction and so the moment it “enters” it goes ok im in aggro range, ok i’m not in attack yet, ok move to player, mvoes the oppostie direction on accident. Ok i’m out of aggro range move to spawn." By sparkzbarca

You nailed it! The ranges scripts where referencing the same script because I was using a stupid public variable -.-', I’ve changed it to a private and retrieve it at start using GetComponentInParent, so each script will get a proper reference to its enemy script. Thank you, I was getting crazy and the game was getting laggy!