- Home /
Editor scripts can't access other scripts in VS
Inside editor scripts, VisualStudio's intellisense cannot see the rest of my project.
As you can see, VisualStudio can't seem to find my PathMover class. Inside the Unity editor, the script works fine, so it seems like a problem with intellisense.
This seems to be an issue with my project since any new projects i create doesn't have this problem.
EDIT:
After some more experimentation it seems to be a problem with my unity version (2019.3.12f1). The 'new projects' i created to try and reproduce the problem were apparently created in an older version. After creating a new project in the same version, i encountered the same problem, so my conclusion is that it's a problem with unity rather than my project.
I have the exact same issue. It seemed to happen after I updated to the latest version of Unity. I tired everything possible. I even uninstalled and reinstalled Visual Studio and Unity no no avail.
Answer by Rachan · Aug 26, 2021 at 12:54 PM
same as me too on Unity 2019.4.13f1
You have to go to Edit > Preference > Eternal tools and click Regenerate Project file
this is should be happen so often, so Unity made this action to a Button everything fixed!!
This works fine. By the way, if you can't see "Renerate Project file" in the "Eternal tools" tab, just click the "External Script Editor" list, choose "Visual Studio Community 20xx", and then you will see the "Generate .csproj files for" option.
Answer by AbandonedCrypt · Feb 12, 2021 at 12:39 PM
Everyone is giving solutions but I don't see anyone mentioning this (which I assume to be the actual solution):
Editor scripts should always be in a Folder (or subfolder of) named "Editor". Editor scripts (inside a folder "Editor") can not see scripts which are not in an "Editor" Folder. Vice versa, non-editor scripts can not access editor-scripts. You can Have "Editor"-Folders wherever you want in your folder structure.
This is simply due to the fact that unity excludes the editor folders from builds, since editor-code is supposed to be used at design-/editor-time and this way unity makes sure that there's no referencing of scripts that won't be present in the final build. @BlueMango10
Editor scripts (inside a folder "Editor") can not see scripts which are not in an "Editor" Folder.
No, that's actually wrong. What would be the point of editor scripts, if they can't access any of the project scripts / data they are supposed to work on?
There's a clear hierarchy of the 4 seperate projects / assemblies that are created by Unity. It's documented over here. There are 4 compilation "phases". Each phase will result in a seperate assembly. Though those assemblies depend on each other in a strict hierarchical way. We have
"Assembly-CSharp-firstpass"
- (depends on nothing)
"Assembly-CSharp-Editor-firstpass"
- Depends on "Assembly-CSharp-firstpass"
"Assembly-CSharp"
- Depends on "Assembly-CSharp-firstpass"
"Assembly-CSharp-Editor"
- Depends on "Assembly-CSharp-firstpass"
- Depends on "Assembly-CSharp"
- Depends on "Assembly-CSharp-Editor-firstpass"
Scripts in one of those assemblies can access anything in a depending assembly, but not the other way round.
So "Assembly-CSharp-firstpass" contains runtime scripts and is compiled first. Those are scripts that are inside the plugins folder or Standard Assets folder. Those can not access anything outside that compilation group.
The "Assembly-CSharp-Editor-firstpass" contains all editor scripts which are in an editor subfolder in one of the special folders from the first group (i.e. inside plugins/editor or even deeper nested "editor" folders). Those editor scripts only have access to runtime scripts from the first compilation group. So they have access to everything defined in "Assembly-CSharp-firstpass".
The "Assembly-CSharp" is the "normal" assembly which contains all your runtime scripts which do not belong in the first group. So all scripts that are not in any of the special folders of the first two compilation groups. Though scripts in this group can access everything from the "Assembly-CSharp-firstpass" group, but not the other way round.
Finally there's tne "normal" editor assembly "Assembly-CSharp-Editor" which is compiled last. It has access to everything that was compiled before.
When you open the solution that Unity generates you should have seperate projects for each group that you have actually in use. Just check the "references" and you will find the DLL of the dependencies I mentioned (if they exist). Note that VS can only "see" the classes in those other assemblies when they have been recompiled in Unity. Make sure you have the Unity Tools installed in Visual Studio. It takes care synchronisation between VS and Unity.
ps: It should be clear that Assembly-CSharp-firstpass and Assembly-CSharp are actually shipped with your game while
Assembly-CSharp-Editor-firstpass and Assembly-CSharp-Editor are not included in your game.
Answer by fblast1 · May 07, 2020 at 02:29 PM
Try this,
First backup your project
Delete .csproj files , .sln file and library folder
Run the project and open any script , see if it fixes the issue
Regards
Thanks for the answer! Unfortunately, this didn't work. After some more experimentation it seems to be a problem with my unity version (2019.3.12f1). The 'new projects' i created to try and reproduce the problem were apparently created in an older version. After creating a new project in the same version, i encountered the same problem, so my conclusion is that it's a problem with unity rather than my project.
it is possible to be an issue since you can reproduce it
try updating visual studio itself to latest version since it might be compatibility issue
Regards
I've just updated visual studio as you suggested, but unfortunately it didn't make any difference.
well you can try two more things :
1-to change api compatibility or 2-check the external script editor inside external tools at preference
restart unity in both
Regards
Answer by BenWiller1989 · Jan 31, 2021 at 09:13 PM
I had the same issue. For me the only solution was the following :
The solution :
1. Go to your Projectmap-Explorer (I am German and don't know how it's called in English).
2. Right click on References and then left click on "add references". The reference-manager-window should open.
3. On Assembly and COM search the "Accessibility"-reference, and on Project the "Assembly-CSharp-Editor"-Reference toggle (should be the first toggle on all three toggle-Lists) and set them to true.
Then click OK and your script should be able to reference all of your classes now, no matter if in the editor or resources folder. You might have to repeat those steps from time to time, if it will uncheck automatically again, so keep it in mind.
Answer by 326piotrek · Feb 09, 2021 at 09:48 PM
Hi, I know it's been some time, but maybe people are still having this issue.
Solution:
Move all the scripts you want to "see" eachother into the same folder. That fixes the problem everytime.
In larger projects I would not want to have all scripts clustered in a sincle folder especielly when external assets come into play. Usually there is a reason why they are sorted the way they are.
Your answer
Follow this Question
Related Questions
UnityVS with VS 2015, CustomEditor classes cant access any game classes 0 Answers
UnityVS with Visual Studio 2015, Editor Scripts cant access game components in VS project file 0 Answers
unity tools for visual studio 2013 Problem 0 Answers
Cant attach debugger | Compile Errors in VS but not in Unity? 0 Answers
Can you script UnityVS's creation of project/solution files? 1 Answer