Custom inspector scripts not able to find target type

Since today all my custom inspector scripts report missing type or namespace issues. As a test, i created these:

  • Temp.cs
  • Editor/TempEditor.cs

looking like this:

using UnityEngine;

public class Temp : MonoBehaviour
{
    public int testA = 1;
    public float testB = 2;
}
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Temp))]
public class TempEditor : Editor
{
    // OnInspector GUI
    public override void OnInspectorGUI()
    {
        Temp temp = (Temp)target;
        base.DrawDefaultInspector();
    }
}

Very basic. Both scripts works flawless in Unity, but Visual Studio 2019 Community gives me errors:

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0246    The type or namespace name 'Temp' could not be found (are you missing a using directive or an assembly reference?)    Assembly-CSharp-Editor    D:\Projects\UnityProjects\LordOfDarkness\Assets\Gameplay\Scripts\Temp\Editor\TempEditor.cs    4    Active
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0246    The type or namespace name 'Temp' could not be found (are you missing a using directive or an assembly reference?)    Assembly-CSharp-Editor    D:\Projects\UnityProjects\LordOfDarkness\Assets\Gameplay\Scripts\Temp\Editor\TempEditor.cs    10    Active
Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0246    The type or namespace name 'Temp' could not be found (are you missing a using directive or an assembly reference?)    Assembly-CSharp-Editor    D:\Projects\UnityProjects\LordOfDarkness\Assets\Gameplay\Scripts\Temp\Editor\TempEditor.cs    10    Active

What is going on here? I checked all over the internet and haven’t found anything that helped me further. I’m hardly an experience C# developer, so this is really difficult for me.

In View->Solution Explorer, check that your Temp.cs is there (there’s at least two projects, Assembly-CSharp and Assembly-CSharp-Editor). I’ve had this (or probably this) issue before where I just had to drag the .cs file into a project there to fix it, but I can’t remember which project - just take a look if it’s missing in either one in the folder structures as displayed there.

Well, that would add that file to the corresponding assembly, which shouldn’t be necessary, as Assembly-CSharp-Editor has Assembly-CSharp set as a dependence, no?

6424940--718283--upload_2020-10-16_16-37-41.png

Otherwise why would it work in Unity? Am i getting this wrong?

Also i would have to add every non-Editor-script into the Editor assembly, which sounds like a pain for a bigger project.

Another thing you could try… close Visual Studio, go to Edit->Preferences->External Tools, click “Regenerate project files” then open your script again from Project window.

Yea, forgot to say i tried that. That actually breaks the dependency to UnityEngine.UI for some reason and doesn’t fix anything. At least i can fix that via the Project=>“Add dependency”-Dialog.