>/head>

How to Avoid Noob Errors when Learning Unity

May 31 / Penny de Byl
You've signed up to a Unity course or found a tutorial online that you like the look of but then you run into trouble, as what's happening on your screen isn't what's happening in the video.  It's a common theme on forums and Q&A boards, but before you go throwing your keyboard out the window or posting a horrible review for the YouTuber or instructor, I'd like to present you with a helpful list of things you should consider; they might even make your life easier.

Above all, remember the instructor (aka me or any other number of a hundred online instructors) wants to help you learn.  It's never our intention to make your life a living hell.  Learning new software is a painful process,  so be patient, take a breath, and consider your best way forward.

To the list...

What version are you using?

While Unity has been pretty stable with the way it looks between versions since the get go, sometimes items go missing or menus are moved around.  I remember when Unity went to a new version and the button I used to turn fog on and off disappeared.  It took me ages to find it.  It used to be a setting on the camera.  It's now in the Lighting menu.

If you are using a different version of Unity than the one your instructor is using, then I can almost guarantee you are going to run into problems.
Write your awesome label here.
If the instructor doesn't tell you what version of Unity to use, you can find it on the top of the window they are using in plain sight.

Using the same version they are using is going to get you started on the right foot to recreate what they are showing you.

It's like trying to learn to drive a Ferrari while watching a tutorial on using a sit on lawn mower!  Well not that bad, but you get the idea.


Write your awesome label here.
Unity provides a repository of most of its old versions.  You can readily find these at:
https://unity3d.com/get-unity/download/archive

Unity also has a series of Long Term Support (LTS) versions which are considered stable and will be supported by the Unity team.  You can find these here: https://unity3d.com/unity/qa/lts-releases

Try and get the exact same version of the one your instructor is using and if not, a version that has the same YEAR and first digit.  E.g if your instructor is using Unity 2020.1.23 and you can only get 2020.1.56 or 2020.1.5 then use that.  

Don't refactor too soon.

You might think you know better than the instructor and maybe you do.  We certainly don't know everything  but if you are following a 20 hour course and writing a game from scratch and you start using variable names that are different from the instructor's,  what do you think is going to happen when you walk away from the course for a couple of days?
Let's say the instructor has:
float numberOfChickens;
in lecture 5, and you add it in your code as
float noc;

Are you going to remember what this is when you type in the code:
for(int i = 0; i < numberOfChickens; i++)
from lecture 18?

Suddenly you have compilation errors because you've named something differently.  It may have worked back in lecture 5 when you remembered your noc was the instructor's numberOfChickens, but now you are just confused.

Of course that's not refactoring as such but it is making your code different to the one you are trying to follow on from.   Let's say the instructor wants you to implement a sorting algorithm using an array and you decide to use a dictionary instead.  Unless you really, really, really, really know what you are doing and are fine with fixing your own bugs, then stick with the content being taught.  If you need to make it run faster, then by all means, once the course is finished and you've got a working project, do all the refactoring you like.

Mine is exactly like yours but it doesn't work.

As instructor's we hear this A LOT.   If your project is exactly like the instructor's then it should work..... 98% of the time and it did work for the instructor as there is video evidence, however granted sometimes it doesn't work because of the computer hardware, operating system or a software bug.
If you have followed the first two suggestions of using the same software version and typing the code in the same, then it could be some other issue that the instructor and her team can't help fix (e.g. if you are running the software on a really old computer or trying out the latest and greatest graphics card driver).

Stop and consider before seeking help if you've done everything exactly the same as you've been asked, also consider the number of students taking the course.  If you are student 1008, then there have been 1007 students through the course and if they didn't have an issue then it's more likely that you've missed a step or not done something quite right.

Having said that, students do find errors and things the instructor has overlooked years after the course has gone live [I think I am up to version 324 of my line/plane intersection video in my mathematics course!!!] and if you have found something is amiss then it helps us instructors make the course better.

Please don't immediately jump to the conclusion that the tutorials are wrong in someway, though.
So what should you do if you think your code/project is the same but refuses to work?  First, don't panic,  it can be fixed.  Second, see if there is a working version of the code/project supplied by the instructor.  If there is, download it and compare with your own.  This is a great learning experience and will help you find the bugs quicker in your own code as you develop your skills.

If you can't find the issue, don't paste the entire code into a forum.  The issue might not be in the code, and out of context the code means nothing to other programmers and students.  Unity is an integrated development environment with many settings outside of the code that can cause errors.

Try to be as specific as possible, as to the nature of your issue.  List the version of Unity you are using (and remember if you are using a different version of Unity to the instructor this might be your actual problem), give details of what you are trying to achieve and what the nature of the issue is, a screenshot of anything useful such as how the project is setup or what is in the Inspector and a screenshot of any errors.  Someone may immediately know what's happening for you and be able to give you help.

If someone needs to see your code in order to help out, they will ask.

Null Exception and Other Errors

If you've used Unity then you've received a nice red exclamation mark in the console.  This means you are dealing with an error.  And be warned, your game might even still run with the error but not in the way you expect.
Write your awesome label here.
So first of all, before you think the funny effects you are getting in your game are the issue, if there's an error in the console you should endeavour to remove it before trying to pinpoint any other issues.  Errors will stop the immediate script from running, but other script might happily keep going.

The most common error is a Null Exception. It means that you have a property that you are trying to use without a value assigned to it.  For example,
Here, location is a Transform, but it has no value. It is essentially empty or Null as the error suggests:
If you take a look in the Console, the error usually tells you where it is occurring.  In this case line 10.  That's not where the variable is being declared on line 6  because there's nothing wrong with that, but on line 10 when it's trying to be used,  location is empty and therefore doesn't have a position.

Another error (and probably most common) is an UnassignedReferenceException.  This is caused when you have a property that is meant to be setup by dragging a gameobject into the exposed field in the Inspector where the script is attached.
I'm sure everyone is guilty of forgetting to do this.  I still get these errors all the time when I press play forgetting to assign a value to any exposed properties. 

These two errors have to be the most widely issued errors by Unity and the simplest to fix.  

With respect to fixing other coding errors, well the list can be as long as your script depending if you are new to programming or not, but the most common things you should check for are:
  • An opening bracket has a matching closing bracket.
  • The name of a property, class, method or game object is case sensitive.  You must spell and capitalise it the same ALWAYS.  numberOfChickens is not the same as NumberofChickens. Having said that, code in totality is case sensitive and spelling sensitive. Be aware that you are writing the EXACT same thing as the instructor.

Google It

Yeah, yeah, everyone says this.  But if you don't know what you are looking for, it isn't that easy.  I mean I can Google an error and find a solution relatively quickly but I've been coding for over 30 years and I can quickly assess if the results from the Google search are going to work for me.

If you are a noob, then it's a minefield of solutions that sort of, kinda, maybe, match your issue and then the solutions are even more difficult to understand than the original issue.

So what should you do?
Write your awesome label here.
You should definitely try and solve the issue for yourself.  That's why I give students challenges.  It will stretch your analytical brain and give you a better learning result than having been given the answer. And if you want to stay in the technology/computer game field then you are just going to have to learn to search and research topics on your own.
If you have a Console error, then definitely copy and paste it into Google to see if there is an easy fix, but make sure you strip the error of any extraneous information.  So instead of Googling:

UnassignedReferenceException: The variable target of Shoot has not been assigned.
You probably need to assign the target variable of the Shoot script in the inspector.
Shoot.Update () (at Assets/Shoot.cs:9)

I would reduce it to focus just on the error because the error doesn't always appear on line 9 of a script called Shoot.cs.  Instead Google:

UnassignedReferenceException Unity

I've thrown Unity in there to focus the search on the software.

Trying this just now I came up with close to 4000 articles.  Less than I had expected but still a lot.  Which ones do you choose to look at?  The one at the very top is not necessarily the best one.  You want to stick with known or authority sources.  Chances are, any of the Unity forums such as answers.unity.com, forum.unity.com or even stackoverflow.com are good options.  You will still find you need a good understanding of what you are trying to achieve to decipher some of the solutions and there might be more than one thing you've done wrong to cause the issue!!  A minefield indeed.

What I would suggest to you, rather than looking through heaps of possibly irrelevant text is to try YouTube.  On the previous search I came across: https://youtu.be/HVucS70Z6Q4  which actually shows you the issue and how to fix it in 2 minutes,  and there will be simple fixes for not only this issue but many other common Unity errors in short videos.

One other suggestion is to ensure the fixes you are seeking out are for your version of Unity or weren't written over 3 years ago.

H3D Forums, Community, Discord and Facebook

For the fastest assistance from fellow students you will find them lurking in the Facebook Group (http://bit.ly/H3DFacebook) or on Discord (http://bit.ly/H3DDiscord) at all hours of the day and everyone likes to help each other out there.  These are mostly for advanced and personalised Unity projects and not for help with our specific courses.  For that you should post in the Community on this site or in the Udemy Q&As.
Write your awesome label here.
Be mindful of timeframes and be patient.  The Holistic3D team is small and we have a lot of students to support, as well as being busy creating new courses and sometimes it takes a while to get your posts.  That's why trying to work out the issue yourself can be a much faster idea.

If you do find a solution to your posted issue before it gets an answer, be sure to share it in the same space to let others know!

Take Aways

Use the closest possible version of the software that the instructor is using.

Never use software that is completely different to the software that is available to you.  It will only confuse you before you even start.  If the software no longer exists.... then ditch the tutorial and find a more up-to-date one.

Refactoring too early is a no-no.

If it is a follow along tutorial then follow along.  Don't make up your own code and don't change the names of variable, properties and methods.  It will just confuse you.

If there's an error with the project it's unlikely it is exactly the same as the instructor's.

Check your Unity version, compare your project with a working download if it exists and ask for help being as specific about the issue as possible.

Do you have Red Console Errors

Fix them. The project may seem to be running, but if there are red errors this can cause parts of your code to be skipped.  The error in the console will also give you a clue as to what line of code the error is on and in which script.

Try Searching

Google can be your friend.  It can also be very scary when you don't know what you are looking for. Only through lots of practice can you determine how it can best serve you.  

Forums

Forums are a valuable source of information.  They are basically crowd sourced solutions to your issues.  But be mindful of other people's time and willingness to help.

Becoming a Successful Debugger

In the end, being able to solve your own programming and game development issues is a valuable task and let's face it you can't rely on the help of others forever (especially if you land that  job).  Becoming an independent learner takes a lot of work but is worth it in the end.  After programming for a while you will start to see the same issues come up time and time again and you will know exactly how to fix them.  I might even go as far as to say that eventually your subconscious will predict impending issues and you will start avoiding them altogether, but it just takes practice and lots of hard work.