How to Fix "MonoBehaviour Not Colouring" Problem in VS Code
Learn how to add colour to your MonoBehaviour when working in Visual Studio Code and Unity Engine
When working in Unity Engine, it is common practice to edit and open your scripts in VS Code. Sometimes, MonoBehaviour, namespaces, and variables do not colour properly when you open the script. This can be a hindrance as colour-coding helps us move through our code faster and locate objects.
This tutorial will help you fix the issue of your MonoBehaviour (and other variables) staying white/black and sometimes, being unresponsive when you open Visual Studio Code.
Fixing the "MonoBehaviour Not Colouring" Problem
One of the reasons Visual Studio Code doesn't colour the MonoBehaviour is that there is no project attached to the script. To fix the "MonoBehaviour not showing colour" problem, you have to manually add the project folder to the script you are working on.
To do that, follow these steps:
If you do not already have the script opened in VS Code, go to the Scripts folder in your Assets Panel and double-click on the affected script. You have now opened the script in Visual Studio.
Click on View in the toolbar at the top of the screen.
In the drop-down, find Solution Explorer and click on it. The Solution Explorer should now open at the left. It will look like the image below. You can see that there are zero (0) projects. Visual Studio does not recognize that the project has been added to the script. You will have to add a project manually.
Right-click on the solution and click on Add in the drop-down options.
Add an existing project to the solution by selecting Existing Project....
When your File Explorer opens, select the folder that you used for your Unity project and open it. The name of my project is MonsterMathIsland.
Select and double-click on the Assembly-CSharp.csproj file.
Your MonoBehaviour and other variables will now be coloured properly. In the image below, MonoBehaviour is now green.
Did It Work?
I hope this tutorial was able to solve your problem and your MonoBehaviour is now coloured.
If this worked for you, or you have other fixes, don't hesitate to share them with me in the comments!