so I worked through the tutorials, good stuff,
but then noticed… wait…ummm how do I debug my code ?
Is there no way to set break points and single step through the code ?
how do you debug ?
so I worked through the tutorials, good stuff,
but then noticed… wait…ummm how do I debug my code ?
Is there no way to set break points and single step through the code ?
how do you debug ?
Most of the time I use print statements in the code. Its not a debugger, but it generally works pretty well. After dropping my awesome java IDE for Visual Studio to use in Unity, I don’t really notice a bit more pain!
prey-tell what is this IDE thou speakesth of ?
can you debug ? ot it just makes the editing much nicer ?
yeah I have this project from another developer, but when I run it, it just sits there… so I have no idea what its doing, or even know where to put any printf’s . I’m at a total loss.
Visual Studio is useful for developing C# code; you get autocomplete among other features etc. It doesn’t really help debugging Unity, except that it lets you code much faster.
You don’t use printf’s, the function is ‘print’, and is usable in any class that inherits from MonoBehaviour. If your class does not inherit from MonoBehaviour, use ‘Debug.log’ instead, which is pretty much the same thing AFAIK.
The output goes into the Unity console window.
thanks for the tips,
maybe its time for me to get a bit more serious about C#
just ‘print’ debugging is gonna make some things difficult though.
btw, does the C# run significantly faster than the J or Boo ?
You don’t have to just use print (Debug.Log()), there is also Debug.Break(), although it’s not ideal, you can pause execution with this call.
As for C# speed, it’s the same as JS or Boo, they all get compiled into CIL, so the only reason one would be faster than the other is the actual code you put into it.
Unity’s JS however does automate a lot of things in the background, which can actually slow down the code a little, so to get the best speed from your code, use the directive “#pragma strict” at the start of your JS scripts. It will cause a lot of the automated parts of the code to become errors, which you can then fix with speedier code.
I personally switched from JS to C# mainly due to the fact there are some language features (like Generics) that aren’t available in JS. It all comes down to preference in the end, but using Visual Studio to write your C# code is fast and very easy once you get the language syntax right.
You can also set the inspector to “debug”, which will show you all your variables for a given script. Combine that with the pause and step buttons and you can do frame by frame inspection of the variables in a script. I’ve not used Debug.Break() but if it automatically pauses that seems ideal for use with the debug inspector. But break at the beginning of a function you want to debug and when it kicks in you can watch the variables in the inspector.