When ever I create a c# script inside the editor it doesn’t inherit from Monobehavior. This seems to have happened when I switched to using Perforce.
Currently to get around the issue I’m having to create a class in VS then add in everything else.
I’m connected to the server inside of Unity using the built in version control and also connected inside VS.
When I create the script it says MonoBehavior but it’s white and not blue/green. I’m able to attach the script to objects in Unity but I obviously don’t have access to Mono features such as Gameobject, etc.
Anybody else having the same issue? Is this something in the project configured incorrectly? As I said this has only been an issue since using Perforce.
It’s still inheriting, it’s your editor that’s broken. Seems like you’re using Visual Studio?
You should be getting a message up about “files has been modified externally” when you create a script from Unity. Make sure to select “reload all” in that dialogue.
When this issue happened a few months back I used to reload all to temporarily fix the issue but now I don’t even get the reload window pop up. I have found that in Unity preferences if I change the text editor to mono and back to VS its fixes it. Again this only a temporary work around.
Old thread but it doesn’t seem to have the answer I needed and it seems to happen on every new script I add with VS open at the time. What I did that has worked so far was to close and reopen VS, this gets my new script in the Solution Explorer. Then I click the Refresh button at the top of the solutions explorer in VS to correct the problem with monobehaviour not being inherited and made my intellisense work again.
It’s an old thread, but I’ve found a solution that doesn’t feel like a hack.
When you have your script open in VS, you will notice it says miscellaneous file in the left top corner of the script window (the window with actual code). That means it doesn’t recognize it as a part of the solution.
You should do the following thing:
have that script active (highlighted blue)
go to File and pick from the list an option that says Move path of the script.cs into:
you will notice the miscellaneous changed to whatever you have your project called
I seem to be having an issue like this as well. In the code it is saying it is deriving from monobehaviour but it doesn’t work when you drag the code to a gameobject, etc.
edit - See my next post for better solution.
A slightly better solution to the one above is to go into Unity->Edit->Preferences…, External Tools and select ‘External Scripe Editor’ and browse for your .proj file. You’ll need to change the drop down list next to file name from .exe to All Files (.) so it shows the csproj file. Select the sln or csproj file and click Open to associate it. Close out of the Preferences dialog and then open your script file from Unity. Now, when you double click on a script file in Unity, it will open the solution and project with references working. However, you may have to manually navigate to your preferred file once it opens. Better but still working on a proper fix.
Seemed to have fixed it. Close any instances to Visual Studio before performing these steps just to be safe.
#1 - Get the full path to Visual Studio (2017 in my case)
HowTo: Find the shortcut icon in your start menu and view the properties.You may have to open the files location and then right click and view properties.
#2 - Copy the full file path to your clipboard. Should copy the entire string so you’ve got something like this but yours will likely be different. “E:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe” #3 - Go into Unity->Edit->Preferences…, External Tools and select ‘External Script Editor’ and paste the path to visual studio without the double quotes and click Open. #4 - You should see the friendly short name of Visual Studio (2017) for External Script Editor now. #5 - Close the Preferences dialog and try double clicking your script file. Should open directly into your project/solution to the selected file.
Came here trying to fix my issue with this. I ended up needing to install .Net Framework 4.7.2 and open the solution instead of just opening the C# file