Is there a way to find out what's causing the bug?

Is there a way to find out what’s causing the bug?
I didn’t think triggers might be the cause.
Game engines have a lot of complex elements, so it seems like it will be harder to find bugs.

What is the bug you are referring to?

There was a bug where you couldn’t attack properly.
Without watching the lecture, you would not have found that the stopAttack trigger of Parameters in Animator was the cause of the bug.

I want to know how to find the cause of the bug.

There are three types of bugs (probably others but I’m sure they will fit under these 3 points in some sense);

  1. Compile Time Errors: The game doesn’t compile. These are the easiest because you just fix whatever is causing it to not compile. These could be a missing semicolon, a typing mistake in a variable name, etc. The reason is in the console and you just need to go to the spot it refers to and see what went wrong.
  2. Runtime Errors: Everything breaks and there’s an error message in the console while you are playing the game. In my opinion, these are usually the next easier ones. It’s a bit of a ‘treasure hunt’ but Unity usually tells you where the error occurred, so from there you need to analyse and see what could cause the specific error and check if that is indeed the cause. This is usually done by just checking if you didn’t miss setting a value in the inspector, or adding some Debug.Log entries to check values, etc.
  3. Logic Errors: Nothing breaks and there are no messages in the console, but the game isn’t behaving as you expect it to, eg. the character only jumps every second keypress, or using an item in the inventory doesn’t consume that item. These can range from really simple to diabolical to figure out. This usually entails just reviewing the logic, sometimes debugging the code by attaching the IDE to Unity, setting breakpoints and stepping through the code line by line as it executes, and loads of other things. It’s a very intuitive process. There is no hard and fast rule for this except experience and knowledge of the code and game you are making.

The bug you mention falls under point 3 above. Some experience and knowledge of the game would eventually lead you to check the animator while the game is running and seeing that the stopAttack trigger was causing the bug. Probably because you would have exhausted all other possibilities. That’s likely how Sam found the issue. As I mentioned, these can be the hardest to find and you will only get better by actually trying to fix these.
You have already gained some ‘experience points’ just by learning about this error. This possible error is now in your toolbox of things to consider when trying to solve these bugs.


Edit
I read through a lot of questions here. I don’t always answer them but I see them. Sometimes someone will answer it and I will read the answer. If it solves the problem, I will now know that the next time I see someone with the same (or similar) question that I’ve seen the solution and can point them to it. Each time, my little toolbox of solutions grow and I gain more experience in solving issues

1 Like

The bug you’re referring to is a tricky one, and can be very difficult to diagnose without having seen it before.
As was explained, if the StopAttack trigger has been set, but nothing has consumed the trigger, then as soon as an Attack trigger is set, the previous StopAttack Trigger comes in and does the job. One of the things I tend to do when my triggers don’t appear to be working is to keep the Animator window open and play, keeping an eye on what’s going on within the Animator.

In this particular case, you might notice that the StopAttack Trigger is set, and that would lead you to question why that would be the case.

One of the tricky parts about using a Game Engine like Unity or Unreal is that there are several places where bugs could happen… could be in the code, or could be within one of may components. Time and experience will help you to better understand where the bugs could be and how to fix them.

At this stage in your Gamedev journey, with a bug like this, most students don’t catch this particular bug. In fact, I’m going to let you in on a little secret: Sam and Rick missed this bug at first and it took a bit of work for them to find it as well.

1 Like

What efforts did you make?
I did Debug.Log() on each method of each script, but couldn’t find it.

Telling people that there is a solution like this in a lecture is like watching a magic show.

As I said, it was very hard to spot. We had debugs going and everything.

It wasn’t until somebody watched the Animator and saw the Trigger on that it was figured out. Now, with lots of experience under my belt, it’s one of the first places I would look, but it sure wasn’t back then.

I found ResetTrigger() and SetTrigger() used together in Unity Docs.
But I don’t know a clear way to find the cause of the bug.

bixarrio and you speak of experience as a core value.
It’s too abstract.

“There are cases where the animation trigger is not working properly and the player cannot attack properly.
This can be solved by using ResetTrigger()."
Can I write this down and think, ‘It would be good to look at this and refer to it’ when I encounter the same bug in the future?

Absolutely, if you find yourself in a similar situation to this particular bug. Or you could use what knowledge you’ve gained from this particular lecture, and remember to reset any triggers that might abort what you’re currently doing, (in this case the StopAttack). You can always ResetTrigger on any valid trigger and if it’s not set, nothing will happen.

Privacy & Terms