Search Unity

Feedback Improve "MonoScript is registered as both Editor and Runtime script!" error message

Discussion in 'Editor & General Support' started by Peter77, Oct 20, 2019.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    The editor sometimes outputs the following error when an asset gets reimported:
    upload_2019-10-20_8-52-33.png

    Please improve this error by including the script name that is causing it. Some pointers how to fix this error would be helpful too.
     
  2. LW

    LW

    Joined:
    Jun 23, 2013
    Posts:
    22
    This happening for me when I have runtime and an editor script named the following:

    Runtime script: MyNamespace.MyScript
    Editor script MyNamespace.Editor.MyScriptInspector

    If I change the editor script name to something more than just appending the word 'Inspector' on to the end it works fine.

    Is this similar to the issue you are seeing?
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    +1 moving around scripts started causing this for me. Not cool.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    The error just started to occur out of the blue once again. Every time I selected a mesh, it would spit out this error. Restarted the editor, problem went away. :confused:
     
  5. MaxRoetzler

    MaxRoetzler

    Joined:
    Jan 3, 2010
    Posts:
    136
    Same in 2019.3.0f3. Using asmdef in the script folder that is causing it, not sure if that has anything to do with it.
    But fine again after restart...
     
  6. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    This is a new error that we added due to a bug that was fixed. If the error is emitted, it means that are still other cases where there are bugs.

    Internally in Unity we maintain caches of which scripts are editor scripts and which are runtime scripts. There was a bug in the editor where the root cause was that the same script was both in the runtime and editor cache. This bug occurred when moving scripts between editor and runtime assemblies, similar to the reports in this thread. Restarting the editor fixes it, because it forces the caches to be rebuilt.

    We fixed the bug and at the same time added this error to detect if this issue could occur under other circumstances, instead of just silently ignoring it and it potentially causing other issues in the editor. And here we are :)

    We will improve the error so it includes the full type name of the script that is causing the issue.

    However, this error should never be emitted in the first place and it would be to great help for us if someone who has a consistent repro for it could report a bug and post the case number in this thread. We have no existing bug reports on this issue. Thank you.
     
    Last edited: Feb 5, 2020
    syscrusher, CristianOG and longsl like this.
  7. rarepop99

    rarepop99

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    54
    As Lukasz mentioned, a bug report for this would be appreciated! :)
     
  8. crener

    crener

    Joined:
    Aug 29, 2015
    Posts:
    27
    Just putting this here as it just happened and annoyed me but I don't have the time to create a proper repo project and doubly check what part of the action caused this to happen... This might help narrow it down somewhat.

    I created a new monobehaviour inside a game side asmdef then created an instance of the behaviour in scene then created an editor for it in another asmdef that was set to not compile, then changed the editor asmdef to compile via changing a platform setting. Change the Editor script and deselect then re-select the gameobject instance in scene view and it happened to me. :(

    Unity 19.3.0f6
     
  9. mobychan

    mobychan

    Joined:
    Apr 7, 2013
    Posts:
    15
    Happened to me as well just now.
    I prepared a package in the Assets folder, including a MonoBehaviour and a corresponding Custom Editor named
    TextMeshProLocalization and TextMeshProLocalization_Inspector.
    When I moved my Package to the Packages folder the error started happening.
     
  10. jzylinski

    jzylinski

    Joined:
    Jul 29, 2019
    Posts:
    4
    I just experienced it as well when I downgraded postprocessing in an attempt to get it to work and rebuit a project. Using Unity 2018.4.22f1. I got postprocessing to work on a build a couple days ago, but after fiddling with some settings haven't been able to get it work since.
     
  11. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Last edited: Nov 21, 2020
    Xarbrough and syscrusher like this.
  12. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    I just got this error as well, and it appears every time I add my script as a component to an object.

    I'm trying to make a package, consisting of just a few scripts. One is a runtime script, and the other is an editor script, along with a script file containing some utility methods.

    Here's the Editor folder and asmdef.
    https://i.imgur.com/yiPuLYI.png

    Here's the Runtime folder and asmdef.
    https://i.imgur.com/cIxjHnS.png

    In the script files, I have also put my classes in a namespace, similar to how Peter77 was doing it in the video.
     
  13. olivier-janin691

    olivier-janin691

    Joined:
    Oct 26, 2015
    Posts:
    1
    Hi guys,

    It seems that it's because you're trying to use an .asmdef into an Editor folder. I suggest you to rename your folder. It worked for us.
     
  14. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I keep running into this issue but don't understand how to avoid it. Can anyone tell what's going on? I won't be seeing the fix from 2021.2 anytime soon because my company only updates to LTS releases.

    Also, how long can it take to fix this sort of bug? Reported at the end of 2019, could have been a candidate for 2019 LTS, and now 2020 LTS has long passed, it gets fixed almost two years later. You can imagine how it feels to have these annoying editor bugs and deal with them for multiple game releases because Unity has too much on their plate, is too busy implementing DOTS or ArchViz while the usability of the editor slowly degrades. Sorry for the rant, but it's been one of those Unity years where the editor is falling apart, but I have to give credit that the player has almost no issues ever.
     
  15. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    I am in the process of backporting this fix to 2019.4 and 2020.3 LTS.
     
    Last edited: Aug 12, 2021
  16. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Thanks! That's great news! :)
     
  17. idlybonddefu

    idlybonddefu

    Joined:
    Nov 1, 2021
    Posts:
    3
    Restart unity. It worked for me
     
  18. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
    2022.2.13f1 Latest as of today
    MonoScript is registered as both Editor and Runtime script!
    It appeared after I added a script and then moved its location to an "Editor" folder because it was an editor script
     
  19. Wilbert-Blom

    Wilbert-Blom

    Joined:
    Aug 13, 2011
    Posts:
    110
  20. jasonpierce

    jasonpierce

    Joined:
    Jan 10, 2023
    Posts:
    27
    Still getting the same error in 2021.3.24 LTS.

    I'm unsure what "fixed" really means, as there are zero notes on the bug report about it. Does fixed mean you won't get the error anymore? You'll get an error but it should tell you the specific thing it is erroring about? Are you required to not put asmdefs in Editor folders? Lots of unanswered questions.
     
  21. SalokaB

    SalokaB

    Joined:
    Feb 19, 2018
    Posts:
    2
    Still getting this error with 2022.2.17. Still no indication of what script is causing it!
     
    MrQuatra likes this.