I just had this issue. Restarting the editor for me fixed the "Scene is being destroyed..." issue. It was strange. It had a "ghost" version of the GUI there saved from when I had stopped playing, even when I disabled every object in the editor.
When I played again I had another error:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.The solution was adding an if condition to the OnDisable:
void OnDisable()
{
if (theButton)
UIEventListener.Get(theButton).onClick -= ButtonReciever;
}
But then I got this error:
Destroying object immediately is not permitted during physics trigger and contact callbacksAll I was doing was a "NGUITools.SetActive" on a panel stored in a variable that was currently enabled.
The SetActive was inside an event reciever which checks the game state, and if it's a certain state, does SetActive.
void StateChanged(GameState gameState)
{
if (gameState == GameState.GameCompleted)
{
NGUITools.SetActive(progressBarPanel, false);
}
}
The state is changed by touching a trigger which increments a value, if that value == something, it sends an event. Then GameStateManager listens to the event and sends its StateChanged event.
The solution to that is here -
http://www.tasharen.com/forum/index.php?topic=1417.0 (delay the SetActive by a frame)
Create an intermediary function you send it it like so:
IEnumerator SetActive(GameObject go, bool state)
{
yield return new WaitForSeconds
(Time
.deltaTime); NGUITools.SetActive(go, state);
}
Then use:
StartCoroutine(SetActive(progressBarPanel, true));
Maybe there is a better way.