Visual Studio doesn't recognize other classes in the same folder?
All of my scripts are in Assets -> __Scripts
I have a class, "N_Analyze" and a class that is attempting to extend it, "N_Gradient" and my main class "Wor_Proj"
So "N_Gradient" has a line that says
public class N_Gradient : N_Analyze
However, in Visual Studio "N_Analyze" doesn't change color, as if the class isn't recognized. Then, when I try to use "N_Gradient" as a type in "Wor_Proj" I get an error telling me that the type or namespace isn't recognized. I'm not using any special namespaces, and all of these scripts are in the same folder in the Project folder. It checks out fine in MonoDevelop, but I'd rather use Visual Studio. Also the Assets folders are in the solution, so I have no idea why it won't recognize them. I've cleaned, rebuilt, rebooted, and it still doesn't recognize these classes. Any advice?
Answer by MaxGuernseyIII · Oct 20, 2017 at 09:40 PM
Depending on how you are using it Visual Studio may or may not automatically find files just because they happen to be in a specific folder. It's silly but there it is.
Some kinds of projects automatically find everything. Other kinds of projects require that you explicitly include files into those projects. .NET Framework projects are an example of that.
The weird thing that gets generated by Unity that looks and smells like a project behaves in a strange fashion. It wants files to be explicitly included but your Unity editor, which is what generates that project, will do that automatically under certain circumstances. Since I almost never use that functionality, I am not sure what they are but I'm certain that closing Visual Studio and double-clicking on a script causes the csproj to be re-generated. I think even double-clicking on a script from Unity while Visual Studio is open will work, too.
I don't like that integration very much. I manage my own assemblies in Visual Studio. I set them to build to Assets\bin and then, pretty much, forget about the Unity integration unless I have to pop open a debugger. The integration still works when you need to do that but you don't labor under its yolk when you don't need it.
I switched Unity back to using Visual Studio and opened N_Gradient. All of the errors are fixed. Thank you very much!
Your answer
Follow this Question
Related Questions
Why aren't my scripts updating in my project? 1 Answer
Protected variable is assigned in parent but null in child 1 Answer
unity visual studios not working properly 0 Answers
Visual Studio can't reference to Firstpass assembly 4 Answers
2 error messages i can't seem to fix (CS0101 and CS0111) 1 Answer