What is the best practice when in search for bugs?

I’m asking this because I’m first time in search of a bug and I can’t find it I know where it must be as I’ve probably written something wrong but how to do in pursuit?

I really have no experience with bug searching as this is my first bug I’ve ever written in 1 year of learning, …

need a very good advice.

I tried rewriting the code from scratch but it seems I wrote same one but a bit differently, …

Highly doubtful unless by learning you mean copy and pasting examples. :wink: First you need to qualify what kind of bug it is. Is it a compilation error? Is it a runtime error? Or is something just not behaving the way you would expect it to?

Unless you’ve only been copying and pasting code for an entire year of programming, or following tutorials to the comma, it is doubtful that this is the first bug. That, or all of us have different definitions of bugs.

In my opinion, best tools:

  1. Commenting out lines
  2. Debug.log/print

Commenting out helps to see that, if you take something out, that the error or such will go away. That’ll help to locate the source of the bug.

The second - and I like this much better - is printing something to the console. You can plan this carefully to see if code goes through and where it actually goes through. Also, you can give feedback on current values of variables or such.

Those are just my two favorite methods, more or less.

Well I’m not copy pasting codes not even close.

By bug I mean the Behavior I didn’t intend to have.

And by learning I was like asking stupid simple Questions on Unity Answers, so I learned basics and writing in basics.

My first bug came in when I started writing more complicated with delegates and events even tho I haven’t found any bugs there yet.

I don’t mean those “run time bugs” like NRE or error that I don’t have correct name or name doesn’t exist, I get plenty of those so I see how differently it behaves and so I don’t need to search through mono but make error and it points me where I need more attention for coding. or it happens I forget something and I get NRE.

And no I’m usually following tutorials only to learn basics than I build my own structure of code.
I also learned I kinda write differently than most. Or maybe we all do.

Are there any else debugging ways?
As I learned this debugging ways on my own.
But never the less I appreciate for your input of your knowledge.

If you’re experiencing weird behavior but there aren’t any exceptions being thrown or anything like that…

You need to come up with a test that your game currently fails 100% of the time, but should really pass 100% of the time. This test has 2 purposes. To force you to come up with reproduction steps, and then also it lets you know when your bug has been fixed.

Without knowing the details of your bug, it’s going to be hard to give more specific advice. But I’ll leave you with this blog post titled “My Hardest Bug Ever” and hope you never have to deal with a bug like that!

Well what is the bug exactly? Bugs can be very generalized but we may be able to help from experiences if we have an idea of what is happening. When I’m trying to find a solution to a bug I first consider “Can I repeat this behaviour?” if the bug is occurring randomly then yes it’ll be harder to track but if you can identify a pattern then you can create break points or print messages around what you believe are associated methods or objects. For example a game I play quite often started to crash on an infrequent and odd basis. I had ALOT of mods installed for this game so I figured one of them broke it. The crash log however was different each time and seemed to be more associated with problems concerning the RAM (I recently had issues with bad ram). So I’m starting to conclude that I should either re-install the game completely or that my RAM is still bad, this is when I found out the game was a 32 bit application and it dawned on me that it may be exceeding 4gb in memory usage. Low and behold it was pretty damn near close to it at startup so I removed a mod that was chewing up the RAM and I have not had a problem since. I should also point out that this mod I removed was one I had installed for a long time and this event did not start occurring until I installed new mods which in turn also pushed the RAM usage higher.

I’m thinking the best way to find the solution to a weird behavior is a mixture of log messages and debugging the code.

First you have to find a method to reproduce your bug. If it occurs all the time than its easy. Otherwise you must find out in which circumstances the bug occurs. Maybe this already give you some hints why it occurs. Than I normally use log messages to isolate the piece of code where it happens. Often I use for that just statements to see where I am. Something like “Enter Awake of class lalala”. On that way I can see easily which method is called when. Most of the time I have now a real good guess why something went wrong. And last I use the Debugger to inspect values of varaibles and check why the code goes these direction or that.

I’m thinking the most powerful tool for bug finding is still the Debugger and you should familiarize yourself with it. Here is a good starting point:
http://docs.unity3d.com/Documentation/Manual/Debugger.html

Good hunt :wink: