The game doesn’t crash at all, I’m just getting a red error message whenever I stop the game and press the IDE’s play button again.
The error says:
Destroy may not be called from edit mode! Use DestroyImmediate instead.
Destroying an object in edit mode destroys it permanently.
UnityEngine.UIElements.PanelSettings:OnDisable ()
The scene contains UIDocument
with a C# script for controlling the UI.
public class MainMenuController : MonoBehaviour
{
public Button multiplayerButton, trainingButton, accountButton, shopButton;
void OnEnable ()
{
var root = GetComponent<UIDocument>().rootVisualElement;
multiplayerButton = root.Q<Button>("multiplayer-button");
trainingButton = root.Q<Button>("training-button");
accountButton = root.Q<Button>("account-button");
shopButton = root.Q<Button>("shop-button");
multiplayerButton.clicked += MultiplayerPressed;
trainingButton.clicked += TrainingPressed;
accountButton.clicked += TrainingPressed;
shopButton.clicked += ShopPressed;
}
void MultiplayerPressed() {
Debug.Log("M");
}
void TrainingPressed() {
Debug.Log("T");
}
void AccountPressed() {
Debug.Log("A");
}
void ShopPressed() {
Debug.Log("S");
}
}
Minor yet important detail: use
– LisaOnEnable
for ui binding code, notStart
Posting a full deep callstack of this exception might help identify the root cause here. It says that it was thrown at
– LisaPanelSettings:OnDisable()
but there is no info what called this method - this often reveals something useful about the context of the error.Sounds like a Unity bug. Could you please file a bug report? https://unity.com/releases/editor/qa/bug-reporting
– Volatilize