OnEnable and OnBecameVisible Question

Hello,
Came across a situation in which code in OnEnable will not work, but the same code will work in OnBecameInvisible. I am just curious as to why. The following are the related variables and code in the functions.

[SerializeField] private TrailRenderer laserTrail;
[SerializeField] private MeshRenderer laserMesh;
private bool onenableForcePrevention;
[SerializeField] private Material[ ] playerLaser;
[SerializeField] private Material[ ] enemyLaser;

private void OnBecameVisible()
{
if (gameObject.layer == 7 || gameObject.layer == 13)
{
laserMesh.material = playerLaser[0];
laserTrail.material = playerLaser[1];
}
if (gameObject.layer == 8)
{
laserMesh.material = enemyLaser[0];
laserTrail.material = enemyLaser[1];
}
}

private void OnEnable()
{
if (gameManager.gameOn == false)
{
onenableForcePrevention = false;
}

if (onenableForcePrevention == false)
{
if(gameObject.layer == 7 || gameObject.layer == 13)
{
laserMesh.material = playerLaser[0];
laserTrail.material = playerLaser[1];
}
if(gameObject.layer == 8)
{
laserMesh.material = enemyLaser[0];
laserTrail.material = enemyLaser[1];
}
rb.AddForce(transform.forward * shotSpeed, ForceMode.Impulse);
onenableForcePrevention = true;
}

}

Please use code tags next time.

And look at the documentation for when OnEnable/OnDisable is called. There’s nothing in the code provided that would invoke OnEnable.

You were right about the order. I had another script that spawned and set the clones layer for the comparison in this scripts OnEnable function. However, the other script hadn’t set the clones layer before OnEnable was called. Must have been slow by just a frame or two. Thanks for the assist.