- Home /
Editing code in debug mode?
I just watched this video. I don't know how, but he seems to be able to edit the game's code while he's in debug mode! - Is this something standard when you code in Monodevelop?
I never use Monodevelop because it's very crashy. I use VS and have UnityVS the debugging plugin. But the problem is I can't edit code, it won't allow me, unless there's an option/setting that I'm missing to enable edit, is there?
Although I'm not quite sure that the guy in the video was using Unity, but in anyway, in general, can I edit my code when debugging in VS and/or Monodev?
From what I know, if you edit the code while the game is running it will crash.
Thanks.
Answer by jbevain · Sep 07, 2013 at 06:53 PM
Visual Studio, with UnityVS, prevents the edition of C# scripts while debugging.
As it has been noted, Unity itself is definitely able to handle serializing the game, recompiling and deserializing the game. The issue is that if you're in the middle of a debugging session it can be really tricky.
Let say you have:
void Update()
{
var s = "foo";
Debug.Log(s);
}
Then you put a breakpoint on the var s = "foo";
line. You run your game, the debugger breaks, and shows the current line.
If you modify the script at that point in time, and add new lines between the declaration and the Debug.Log call, you'll have the feeling that you're modifying the current running method. And that if you step you'll step into the new code. Sort of like you can do it in Edit & Continue with .net. Except it's not the case.
As Unity doesn't support Edit & Continue as Visual Studio understands it, it prevents the edition of scripts while debugging. Which is not that big of an issue as you can very simply detach, modify the script and re-attach the debugger afterwards.
"modify the script and re-attach the debugger afterwards." - wish I could do that. but as I mentioned, my game seems to crash whenever I attempt to edit code. am I missing something?
This seems to be an isolated issue. Your Unity is crashing when you do that (and someone else's too), but for the majority of people it seems to work. I think reporting a bug/crash report would be the next step from here
It's not that 'Unity is crashing' - it's the game that does. Even in the slightest changes, like changing the string of a debug.log! Idk, gonna have to dig more into it.
@vexe Unity uses serialization in order to "save state" objects. If a variable doesn't need to be preserved between recompiling, then there is no need for it to be serialized. Unity also uses serialization for the inspector. So any prefab is really just a collection of serialized "save state" objects.
Think of making something "recompilation proof" the same as being able to save the entire scene as a prefab and then re-instantiate it after recompiling. Anything that needs to stay between compiles must be serializable.
Answer by Will Davis · Sep 07, 2013 at 11:14 AM
With the exception of Shader changes, unity does not recompile code whilst in play mode I believe, you can edit and save code however, but it will not recompile in unity until you stop playmode. Although I do sometimes get issues debugging and making changes more so when the debugger has caught a breakpoint etc.
Also I seem to remember in the mono settings we had a reason to specifically set it to not build in mono (tools>options> scroll down to Unity >debugger..
Hope that helps :)
This is incorrect. Unity compiles code while in play mode. However note that only serialized data will persist through the compiling
I edit code in Notepad++ and am having no issues with this feature
Yep I stand corrected. It does seem to run through the code on all updates, never noticed as I've always had to stop/play for the build to show changes but it does not appear to affect the running build.
How are you attaching notepad++ to the debugger.. I didn't know it integrated that much?
You look it up on google, like I did. Theres even a wiki page which tells you how to quite literally "replace" monodevelop with Notepad++
Your answer
Follow this Question
Related Questions
Monodevelop and Visual Studio 2015 debugger skips frames 0 Answers
Visual Studio 2015 debugger can no longer attach to Unity after installing RC3 1 Answer
Debugger not working in unity3D 4.1.3f 1 Answer
monodevelop vs visual studio? 1 Answer
debugger halt after start(), can only resume in update 0 Answers