Custom Editor and Visual Studio 'Solutions'

I am attempting to create my first custom editor in unity. This is a script called PlayerEditor.cs.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class PlayerEditor : Editor
    public override void OnInspectorGUI()

When I open the script in Visual Studio, it gives an error of "The type or namespace name ‘Player’ could not be found. This is what Visual Studio’s Solution Explorer looks like.

As you can see, it loads as two projects. The PlayerEditorscript is in the folder Project/SpaceShooter/Assets/Editor. The actual folder structure is correct, but VS Solutions thinks they are two projects. If I manually drag the Editor folder to the Assets folder in the VS Solution explorer like so,
the error resolves. Player is now found in the namespace. I can create custom controls and it works fine. The only problem here was Visual Studio thinking the scopes were different. The actual folder structure has not changed at all. This would be the end of my troubles, but every time I reload, and sometimes just randomly, VS removes the Editor folder from the first project.

So far I have tried deleting all the CSProj files and all the SLN files and reloading. Visual Studio rebuilds on opening again but does the same thing. I’ve tried moving the Editor folder to different locations like my script folder. This doesn’t work either.

How does VS determine what cs files belong to which projects? Can I tell VS that the folder Editor and its contents are meant to be in the same project as everything else? Does anyone else have this problem?


I figured it out after hours of trying everything. The fix was so easy too. It was some kind of version mismatch between my project and the installed version of Visual Studio. If anyone else has the issue, try the following steps:

  1. Open Unity Hub
  2. Click on Installs in the right panel
  3. Install the latest version of Unity and make sure that Visual Studio is selected in Modules
  4. If your project is older, make sure to change the Unity Version of your project to the most recent one. This might break stuff, but it’s always converted fine for me.

If that doesn’t work
Uninstall the latest version of Unity from the Installs tab and then follow the previous instructions again.

Apparently this was a problem with the way Unity defines Visual Studio’s code checking between versions. The VS Solutions window still breaks it into three projects, but the namespaces are correctly referenced between the projects.