How to Handle Errors in Unity

preview_player
Показать описание

In this video, I'll show you how to handle errors in Unity.

#Unity3D #UnityTutorial #GameDevelopment

Exception handling is an obvious solution to errors that arise in your code. This, however, isn't always the best approach - in fact, I'd argue that it rarely is.

In this Unity tutorial, I'll show you the ins and outs of Unity exception handling and Unity error handling. I'll cover what it is, how it affects your game, and when you should use it.

If you'd like to follow along, feel free to download the project using the link below.

My Favorite Unity Assets 💯⤵️

* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
Рекомендации по теме
Комментарии
Автор

Did anyone else notice the chemistry going on there?

Автор

Why does the profiler still show red spikes at 4:39 if the code was fixed?

Lordlives
Автор

Beautiful work man,
Another reason to care about performance other than low end device is,
You can use time you saved from start, to help in polishing by adding more stuff later.

ashwanishahrawat
Автор

This is a great format, super helpful for exploring concepts by seeing the thought process of the programmer

invntiv
Автор

At first I was like "do I really need a skit for this" - but honestly great execution and the format was worthwhile

MattygFTW
Автор

Just wanted to say that I really like this format.

Zeekar
Автор

I would like to politely disagree with this video. While the point about the cost of throwing exceptions is well taken, I think its important to balance that against the cost of the alternative. Simply "handling the exception", in practice means one of two things: either fixing the error immediately, which is always ideal but in practice not always possible, or burying the bug. If, in the above case, simply returning the player position is not the ultimate intended functionality of the application, then you are introducing unintended consequences into the application, without hinting at the existence or the location of the bug. When you, or someone else on your team who is not as familiar with your implementation, is tasked with fixing the bug several days, weeks, months or even years in the future, depending on the scope of the project, they are going to have to invest substantially more time in understanding, isolating and eliminating the error, than if you had just thrown the exception. This cost can become exponential if you never throw exceptions because now every bug is buried. Yes, you can Debug.Log or throw a warning instead, to notify a person of the error, but those also have processing costs so at that point it is a 6 of 1 half a dozen of the other kind of thing. Obviously, if your consul is posting one or more exceptions every frame, there are going to be serious performance costs, but the response should be to fix those errors prior to the game / patches release, not to do away with throwing exceptions all together. So while it is always possible that live code will throw an exception on occasion, if you failed to catch some obscure bug, I personally think that hit to performance is worth releasing an, overall, less buggy game at launch.

brendanconlon
Автор

That makes so much sense. Guess it isnt called "Exception" instead of Error for no reason.

MrAntiKnowledge
Автор

Love this format... I guess I'm getting addicted to these lessons! Thanks!

RobertoDeMontecarlo
Автор

Honestly love the skits you do for your videos man, so refreshing when looking for something for unity :)

bhilder
Автор

I get a bunch of random errors that have nothing to do with scripts. Tried clicking them, right clicking them, and double clicking. Nothing works.

Anothuor
Автор

Hey Charles! Great video as always. I would suggest to speed up the video and pack it up within 2 or 2 and a half minutes. It's really good as it is. To me, it would have been even better to get the information a bit faster! Cheers! :)

rakibjahan
Автор

Just wanted to pop in to day that I really enjoyed this format and video length. Keep up the good work!

brodendangio
Автор

Keep up the great work, really like the format of this video :)

RobertBrunhage
Автор

I like this setup of questions and answers. Breaks it down for dumb people like me!

clipartinc
Автор

Excellent advice / excellent presentation 💪🏾👌🏾

tnkspecjvive
Автор

Thanks alot for the effort! Sorry to say that the music is so distracting for me that I cannot follow :( Turning off audio and sticking to subtitles also doesn't work for me (which Charles is talking when?). kind regards

octoponx
Автор

If I have a SerializedField that the programmer forgot to set via Editor, is it OK to throw an Exception on Awake/OnValidate/Start to let the programmer know he forgot something?

goldenimper
Автор

Please help mee how can i fix this?
( error cs1519 invalid token '}' in class, struct)

differentlanguages
Автор

Hey look! It's the Adventures of Man and Man!


Better than Rick and Morty if you ask me! :D

ZoidbergForPresident