Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Visual studio doesnt recognize "Editor" folder as part of the project

Discussion in 'Code Editors & IDEs' started by pertholdth, Apr 21, 2024.

  1. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    So as the title says, my visual studio does not recognize editor scripts in the editor folder as part of the unity project

    It does not provide intellisense for editor scripts

    When using "Find", and selecting "search in project" or "search in whole solution", keywords existant in editor scripts wont be found


    The scripts still compile and the unity console displays errors in the scripts if there are any


    What I have tried:
    • Installing the most recent updates for visual studio
    • Removing the visual studio package from the unity project, and re-adding it
    • in preferences External Tools, removing and reassigning visual studio as default IDE
    • Regenerating .csproj files for the project, all boxes checked

    None of it worked, the problem remains. For reference im on 2021.3.37f1 LTS


    Any advice on how to fix this would be appreciated
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,390
    This is just how it works. Scripts in Editor folders get compiled into a different assembly (Assembly-Csharp-Editor). Said assembly references the main assembly, Assembly-Csharp. Assembly references can only be one-way, so anything in the Assembly-Csharp assembly cannot use anything in Assembly-Csharp-Editor.

    You will find that your scripts in editor folders can access all your runtime code.

    So you need to think about why your runtime code is trying to access editor-only code, and perhaps revise your approach.

    The order of references is described here: https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html
     
    Ryiah likes this.
  3. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    837
    Just to clarify for testing reproducibility, which Visual Studio version and Visual Studio Editor package are you using?
     
  4. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    thanks, well, its because i am using editor scripts that call the same method that is used during runtime, and it seems like a waste to duplicate code, but if thats how it is, thanks for the answer

    for clarification its the editor scripts that want to access the runtime scripts, not the runtime scripts that want to access the editor scripts


    Im using vs2022 17.9.6
     
  5. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    837
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,390
    Okay well editor scripts should be able to reference runtime scripts just fine. You're not using assembly definitions?
     
  7. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    837
    This works perfectly fine:
    upload_2024-4-21_2-34-25.png
    upload_2024-4-21_2-35-1.png
    upload_2024-4-21_2-35-36.png
    upload_2024-4-21_2-37-29.png
    upload_2024-4-21_2-39-52.png
    Something screwy seems to be happening on your machine, do you get this on even a barebones project?
     
    pertholdth likes this.
  8. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    you are right, just tried on a fresh project and it works there

    seems like my main project has the editor folder somehow messed up, how can I fix that?

    i have tried also deleting the library folder but didnt work either
     
  9. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    837
    Maybe try manually deleting the .csproj and .sln files in the project root yourself, then regenerate the project files? (Should also automatically regenerate when using the "Assets/Open C# Project" action)
     
  10. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    deleted all .csproj and 2 .sln that i had

    then did assets > open c# project, issue still persists

    also tried deleting the editor folder and recreating it, also doesnt work


    something is messed up since a fresh project works evidently
     
  11. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,390
    Click on the script and check what assembly it is being compiled into. Is it being compiled into Assembly-Csharp-Editor?
     
  12. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    i seem to have found a clue

    apparently, when i open a script from the editor folder, its coming from "miscellaneous Files", and not from the assembly csharp editor

    Untitled.png

    is this enough of a clue for a fix?
     
  13. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    it seems like you are right, its not, it shows "miscellaneous files"
     
  14. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,390
    Was talking about this when you click on a script asset:
    upload_2024-4-21_20-42-55.png

    What assembly is it showing
     
    pertholdth likes this.
  15. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    Untitled.png
     
  16. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    837
    pertholdth and spiney199 like this.
  17. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
  18. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    190
    that was it, i had to force load the assemblys, they were labeled as "incompatible", and instead assembly chsharp.player was being used

    thanks friends for the help
     
    Last edited: Apr 21, 2024