I am trying to have multiple objects respond to a game pause state, this works fine when first running the scene however after restarting the scene the listeners are responding at different times.
The event that sends the message is:
globalGameState = newState;
GameStateChanged?.Invoke(globalGameState);
And the listener:
private void OnEnable()
{
Globals.GameStateChanged += GetStateChange;
_correctState = false;
}
private void OnDisable()
{
Globals.GameStateChanged -= GetStateChange;
}
void GetStateChange(GlobalGameState state)
{
if (state == _compareState) { _correctState = true; return; }
_correctState = false;
}
I have checked and made sure that all the objects are subscribing / unsubscribing to the event correctly, I just cant find what would cause it to stop working only when the scene has been restarted. (The scene restart is a simple SceneManager.LoadScene();)
Debug messages
[Before scene reload:] https://i.stack.imgur.com/eUDjl.png
[After scene reload:] https://i.stack.imgur.com/J7Tla.png
In the second image there are 8 that run on a different timer, every pause or restart after that it is always the same 8 that are de-synced. Restarting unity changes the number in the de-sync batch.
Any idea as to why some are receiving the event on a different timer is welcome.