Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug "Destroy may not be called from Edit Mode" whenever I try to add UI Toolkit to my project

Discussion in 'UI Toolkit' started by xDoHn, Jun 1, 2022.

  1. xDoHn

    xDoHn

    Joined:
    Jul 25, 2018
    Posts:
    8
    I've been trying to get UI Toolkit to work on a project in Unity 2022.1, but whenever I add a document to my scene, make any kind of basic template for it and run it I get an error on my console, apparently caused by the Panel Settings Asset.

    upload_2022-6-1_4-31-58.png

    The Panel Settings Asset I'm using is the default one you get when you create one. I tried to keep everything to default, including the UI Document, the template (I just added a text to see something on screen) and the panel settings asset, but I still get this error.

    I also tried this on Unity 2021 LTS and I get the same result.

    This happens always when I'm in Edit Mode and I press play from there (I assumed it has something to do with the UI in Edit Mode being cleaned up before entering Play Mode).

    The game runs fine otherwise, and the UI seems to work, but this error doesn't allow me to compile the game.

    I have no code running on my scene, and the UI Document has no added components to it, it's just the default UI document.
     
  2. ccfoo242

    ccfoo242

    Joined:
    Oct 9, 2014
    Posts:
    85
    I'm seeing that as well in 2021 lts. Doesn't effect the game but every time I stop playing it logs that.
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    979
  4. xDoHn

    xDoHn

    Joined:
    Jul 25, 2018
    Posts:
    8
    Are you able to package the game? My game works fine as well in Play Mode, but that error appears when it compiles so I can't package my game.
     
  5. ccfoo242

    ccfoo242

    Joined:
    Oct 9, 2014
    Posts:
    85
    Yeah I don't have any problem with Windows or Android builds (only ones I have tried)
     
  6. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    68
    @xDoHn I have this cause my builds to fail too, however I find that it only causes the first build attempt to fail - I can build again immediately after the failure and it works the second time.
     
  7. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    You can switch to an empty scene in your project and then start the build. Then the stated error does not occur and the build works without aborting.
     
  8. StripeGuy

    StripeGuy

    Joined:
    Dec 30, 2016
    Posts:
    52
    I'm sure it's not the right solution, but it worked for me...I disabled the Event System component and the error disappeared. I'd love to find a real solution, since most people will need that Event System.