Search Unity

Solve your scripting issue check list/mini guide

Discussion in 'Scripting' started by CodeCody, Nov 3, 2011.

  1. CodeCody

    CodeCody

    Joined:
    Apr 27, 2010
    Posts:
    440
    Preface
    This thread serves as a check list to common problems to look for when you run into a problem well programming. This is NOT a tutorial for learning scripting in Unity. If you are looking for tutorials for Unity please go to the Teaching section.



    Step 1: Check it
    The first thing you should do is make sure you do not have anything wrong with your syntax and/or spelling. This can be many simple mistakes such as;

    • Missing or extra brackets
    • Missing or extra parentheses (hate this one)
    • Misspelled words. transform works, transfrom does not
    • Incorrect case letters. Their is a big difference between GameObject and gameObject
    • Lack of semicolon ;
    • Function not being called or conditions never met. In some cases your section of code is not even being called. To check this use the "Debug.Log();" to check if your code block is actually being called. Multiple Debug.Log's can also be used to check what order you code is running in.
    • And of course the dreaded comma instead of a period. Known to cause utter chaos.
    Step 2: Check it... again
    Is your script good but still not working? Perhaps it is not a problem with your script after all!
    But rather a issue in the unity editor? For example:

    • You did remember to actually set the inspector values... right?
    • Is the script actually attached to the object? So simple right? However failure to check can lead to many hours or even days of headbanging... not that I would know...
    • OnCollision/OnTrigger functions not being called? Make sure to check that isTrigger is set correctly. And remember a rigidbody must be attached to one of the gameObject's for the function to even be called in the first place.
    • Debug.Log only displaying once? Toggle "Collapse" in the console to off (shown as on in the photo):
      $Console-0.jpg
    Step 3: Search it
    Still not working? Well then it is time to look for help online, BUT WAIT! This does not mean go directly to the scripting forum and writing out a thread. Before you even think of doing that use the mighty powers of Google! 90% of the time your question has already bin asked and answered, on ether the forums or somewhere else... many times, sometimes...

    Oh and don't stop with a single search, try multiple forms of wording of your question. Tip, if your looking for something unity specific. Searching with "unity" before your question can help filter out unrelated information.
    Step 4: Sleep on it
    By this point you are probably going insane. And at that, just stop working on it. Creativity seems to flow more slowly when frustrated. So work on something else or take a break.
    Step 5: Start it over
    Sometimes their is no way to fix your script because it's logic in itself if flawed. If you ever find yourself in such a circumstance, then it might be time you tried a new approach.
    Step 6: Ask it
    Alright are you sure nobody has asked your question yet? Then ask. You will find many people on the forums/unityanswers are willing to help. And as long as you actually tried to find the answer yourself, most will be happy to do so. But in order for someone to help you the must find and be able to understand you question. Some tips for posting questions:
    • Use a descriptive title to your thread. Titles like "HELP ME" or "NEED SCRIPT FIX NOW!!!!" will not help you. In fact this can act as a deterrent to other programmers. After all what thread would you open, the proper and descriptive question; "How to normalize a vector3" or the noob yelling; "NEED HELP SCRIPT NOT WORKING" at you to do all the work?
    • Try to use correct grammar and spelling in your thread. If that is not your best subjects or English is not your first language. Don't worry write it your best and be descriptive, it will help to improve the odds of someone understanding your question.
    • When posting your code, be sure to use the"code" tags. This will make it much easier for other people to read your script. For example of code tags click the link. A example of code tags in use:
      Code (csharp):
      1.  
      2. var foo : int = 0;
      3. function Start(){
      4.      Debug.Log("Hay look I'm a dummy script");
      5. }
      6.  
    • Do not! Post your question in multiple sections of the forum. This is frowned upon by many users. Instead find the one forum that best describes your question and post there.
    • Do not over bump your thread. It does not have to be at the top to be answered. A normal accepted limit of bumping would be once every 1 or 2 days.
    Well that is about everything that I can think of. Feel free to comment if you find anything that needs correction or clarification.
     
    Last edited: Nov 26, 2011
  2. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    sticky ;)
     
  3. CodeCody

    CodeCody

    Joined:
    Apr 27, 2010
    Posts:
    440
    Would be nice lol, thanks.
     
  4. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    This is true, but we are the point where people don't want to figure it out. They want others to do it for them.

    Questions like "How do I add score!?". When I came to unity it looked like a professional engine. But going through forums it seems rather filled with particulary easy questions that could be solved with a simple google.

    This is why I think that "Ask it" should be the last step, unless you are completely stumped on how to do a particular problem then maybe asking and learning how someone else encounters it is the best fix.
     
  5. CodeCody

    CodeCody

    Joined:
    Apr 27, 2010
    Posts:
    440
    I would have to agree with you. For some reason that did not occur to me, will edit now.
     
  6. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    Much better :) Hope it gets a sticky, it's set out well. :D
     
  7. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    is there a reason why you omit "normal" debugging? put some debug.logs and output values or se what code blocks are executed in which order. pause the game and check the variables in the inspector or step through the code with mono develop debugger.
    when your code does not execute correctly the chances are high there are several errors inside. so asking in forums may not even reveal all.
    and dont forget that you have best chances to find the errors as others usually dont have your whole project (if they had they still lack intention). and developing proper debugging techniques is essential for any serious developer. you cant always run to the forums crying when something is not working well. so training debugging is the best you can do.
     
  8. CodeCody

    CodeCody

    Joined:
    Apr 27, 2010
    Posts:
    440
    Ack forgot about Debug.Log! Thanks for reminding me. Good advice as well.