I cannot put some breakpoints in Visual Studio 2015 to debug my Unity project. It seems to allow breakpoints 50% of the time, but it happens consistently across unity projects. I don’t have this problem with other types of VS projects.
Visual Studio tools for Unity is installed.
Things I have tried:
Reinstalling Unity, VS and VSTU
Running as administrator
Re-creating a project by scratch (deleting folder + re-importing all the assets)
Deleting the Library folder
Deleting project settings
Changing advanced build settings “debug info” from “pdb only” to “full”
This generally happens when somnething in the source (or the project file) has changed, so it’s not sure if it can hit the breakpoint. This isn’t specific to Unity but it looks like something changed that’s causing this behaviour with 5.5.1. Something is changing a code file somewhere. Close the solution in visual studio, then reopen it by clicking a .cs file in Unity and see if that makes the issue go away (at least temporarily).
This is what I did:
Close solution → double click .cs file in Unity → solution opens (in another VS instance) → Attach to Unity → Start Unity
But the breakpoint is still not being hit.
I checked the files in the Assets folder and the .proj file, and none of them have changed between the time I open the solution and the time I start unity.
Well, mine suddenly started working again. I have no idea why.
My breakpoints still have that error message, but only when they are on scripts not attached to the current scene.
When I load a scene they activate and break appropriately.
It’s possible that something I did in the OP fixed it, although it wasn’t apparent because the breakpoints still showed the same message.
Deleting my sln and csproj files got me to a state similar to where soreric was at in the latest post: The breakpoints still say they are broken, but they work. When a breakpoint is hit, the false broken icon / message goes away. I only tried this on one file, so I am not sure if hitting one breakpoint would solve the erroneous messaging globally.
The script I was testing was attached to an object in the scene. I did not check any other state.
Here’s something interesting to check… take one of your new .cs files and open it in Notepad++. First:
Click the “Encoding” menu and make sure it’s set to “Encode in UTF-8”. Not with the BOM, just the Encode in UTF-8 option.
Next, click the “Edit” menu. Go down to “EOL Conversion” and see what that’s set to. If it’s set to “Windows” then that option will be greyed out. If it’s not, then select it. Then open that .cs file again in Visual Studio and see if the breakpoint can be hit.
I did it. After this a breakpoint still couldn’t be hit. But after first running a game it fixed. I change encoding in only one new .cs file and breakpoints fixed in all new .cs files. This is strange. But I think it was a reason of my problem.
Maybe is there a way to create new .cs file in correct encoding in unity?
Thank you for your help.
That’s the only thing I could think that Unity might have changed that would have caused this. It’s possible the new docs are getting created as UTF16 or UTF8 with BOM and Visual Studio is getting confused and doesn’t know how to map the code in the file to the generated byte code (so doesn’t think it can hit the break point).
I have the same problem when I update the version from 5.4.3 to 5.5.2.
I found my problem is because my xxx.dll reference the old version “UnityEngine.dll”. so I change the reference file with new version, and it working right now.
I don’t know if it will work for you.