Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by unity_vsTV9-2kQ2WK-w · May 30 at 04:00 PM · unityeditoruitoolkit

(UI Toolkit) "Destroy may not be called from edit mode" on game start


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 Start()
     {
         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");
     }
 }


Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andrew-lukasik · 6 days ago 0
Share

Minor yet important detail: use OnEnable for ui binding code, not Start

avatar image andrew-lukasik · 6 days ago 0
Share

Posting a full deep callstack of this exception might help identify the root cause here. It says that it was thrown at PanelSettings:OnDisable() but there is no info what called this method - this often reveals something useful about the context of the error.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OleksiyNosov · Jun 03 at 03:01 PM

Hey, I have the same problem


I tried disabling my previous prefabed EventSystem in the scene, and the error does not appear after that.


Still don't know the root cause of the problem but hope that it will help

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

192 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why should I use 'SerializedProperty' ? 0 Answers

I updated my unity project and now the post proccesing package doesnt work anymore. 2 Answers

The unity collab button doesnt appear on the editor 2 Answers

Unity 2020.1.0a14 Failed to present D3D11 swapchain ,UNITY 2020.1.0a14 BUG Failed to present D3D11 23 Answers

I opened new project and getting as no custom tools available and while running the scene its diosplaying toggle error. please check and help me out i am a newbie 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges