I have a MonoBehaviour Script with OnDestroy implemented, with a simple Debug log
When running the game from the editor, whenever I switch from a normal Game window to the maximized, or from maximized to normal, the debug log is printed in the console, and any other code in OnDestroy is also executed, however, the game object was never destroyed.
Is this a bug, or known, I have not found documentation on it.
It’s making debugging pretty frustrating as OnDestroy is meant for when things are actually being destroyed, so code is executing when it shouldn’t be.
That seems odd, but I wouldn’t be surprised honestly.
Historically OnDestroy() has been a troubled function, often requiring silly shims like public static bool applicationIsExiting; and annoyingly hairy code interlocks to prevent fiddling with things that might new up GameObjects such as singletons and whatnot.
Instead, try and move stuff out of Awake / OnDestroy and instead put it in OnEnable / OnDisable.
The OnEnable / OnDisable lifecycle pair is FAR more robust and reliable.