Unity3D Mistakes I made that you should avoid

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Synopsis for those who want to know if the video is worth watching for them:

  1. If you want to move objects in fixed patterns, use the animation system and timelines instead of code.
  2. Use the audio mixer
  3. Not every class in your game's codebase must be a MonoBehaviour
  4. Use prefabs
  5. Avoid Find and FindWithTag, because they are slow and fragile
  6. Learn how to use the Profiler to analyze performance problems
  7. Avoid destroying and instancing game objects too often. Consider deactivating and reactivating them instead.
  8. Some asset recommendations: Cinemachine, DoozyUI and TextMeshPro
  9. Don't be afraid of publishing your games in order to get feedback
👍︎︎ 8 👤︎︎ u/PhilippTheProgrammer 📅︎︎ Feb 19 2019 🗫︎ replies

Overall a very useful video. But, it's really frustrating that he says to avoid using GameObject.Find/ByTag and Camera.main, but does not give an alternative. I assume it's to assign it directly in the editor? But I'm not confident of that guess, because it seems to have some of the same problems: public GameObject x doesn't give me a lot of compiler protection. public ScriptClass x seems a lot better. Maybe that's what he thinks is better, too?

👍︎︎ 3 👤︎︎ u/AcademyOfFetishes 📅︎︎ Feb 19 2019 🗫︎ replies

I only saw the first tip so far, but that was useful. So when can you use animations for movements like this? Is it only when the objects aren't going to interact with the world?

👍︎︎ 2 👤︎︎ u/AcademyOfFetishes 📅︎︎ Feb 19 2019 🗫︎ replies

Must instantiate bullets from my instantiated soldiers in order to destroy the other bullet instantiating instantiated soldiers who are wearing a different color uniform, and no one can stop me! Ah hahahaha!

👍︎︎ 2 👤︎︎ u/MaskedImposter 📅︎︎ Feb 20 2019 🗫︎ replies
Captions
[Music] hey there Jason here from unity3d college today we're gonna talk about common mistakes that developers make when they're getting started with unity now I've seen these mistakes made by new programmers who are just getting started and experienced developers who work in web projects or Enterprise things and just know what they're doing but they're just a little bit new to unity so let's get started now the first problem I see new developer struggle with or especially experienced developers who have a slightly different background struggle with is not taking advantage of all of the things that are in the editor and not using the editor properly and instead trying to code features that already exist so say for example I've got a boat here this little red boat and I just want it to sail around a little bit perhaps it's just like an idle thing where the boats going back and forth maybe even a tutorial or some kind of a script where the boat needs to go from one place to another turn do a little bit of stuff like that what I usually see people do starting with is just start writing code so they'll create a script a tutorial boat script for example give it an array of positions keep track of the next position in an integer so we know exactly what position we want to go to then write an update loop that maybe checks the distance to that position increments it if we've reached the position and then looks at where we want to go and slowly moves us forward with transformed translate maybe x speed and delta time because we want it to be frame rate independent and controllable but you get the idea this is what I see a lot of the time and in fact to be honest it's same kind of thing that I did when I started I built an entire tutorial system doing stuff like this to move my things around now I did it a little bit more advanced than that but get the idea I still did it all in code and it was a really bad idea because there are some much much better options now for something like this oh let's hit play first and just watch what happens I'm gonna hit play and watch my boat oh look it flipped sideways it's acting weird and now it's just shaking back and forth it didn't even really do my turn like it was supposed to so you get the idea it's not perfect and I to do a bit of work to kind of clean this up now the reason it's flipping over by the way is that the forward axis is up and down that's that blue arrow so when I rotate it and use that look at or look towards it's a pointing that forward direction there so I'd have to parent this to another object whole big mess there's an easy alternative though if I open up my second demo scene here you can see that instead of setting up a boat with a script like this I can set up an animation so here I've just created a boat with an animator on it and an animation and I can hit play and it all kind of sail around and go back and forth and actually work now it's not beautiful because my animation skills aren't that great and I didn't spend that much time on it but it's a whole lot easier to set up and a whole lot easier to edit now if you wanted to do this yourself let's select this boat we'll remove that script and then we'll just go to the animation window and hit create and create a new animation I'll call this boat 2 and then we'd enable our boat first hit the record button and be in the movement mode which is just W on the keyboard or right here then maybe move it a little bit get a first keyframe then I select a point on this animation timeline now I use the mouse wheel to zoom out and this is in seconds that's one second two seconds three seconds I go like one second drag it over here BAM go to 2 seconds drag it over here oh yeah drag it over here and then maybe go to three seconds and drag it over here and even rotate it whatever this direction you notice that the rotation is getting added I could even maybe scale it up so it rotates and scales then I can stop recording hit play and watch my entire animation just kind of go like that our boats going going going slowly growing as it animates and I didn't have to write any code I don't have to mark down any positions it just kind of works now this kind of thing works for UI elements game objects obviously tutorial stuff another thing I see people struggle with is setting up audio levels and audio mixing systems I've seen a lot of people build these not knowing that there's already an audio mixer built right into the engine so if you want to do some leveling or attenuation or just muting channel adjusting channels based on different things check out the audio mixer and definitely use it but just again remember there are a lot of these built-in systems that are there to cover all of the really common things so if it's something that you think is common in a video game there's probably a system in there that you should check out and learn about before you try to build your own now let's go on to some non editor stuff one of the most common issues I see for new developers in unity is overuse of mono behaviors when you create a script in unity it by default makes a mono behavior so you right-click hit create new c-sharp script you're getting a mono behavior but you don't necessarily need one for everything in fact you probably don't need one for most things it's just that the way that the engine works and the way the workflow is it kind of leads you in that direction so you need to watch out for that and just try to minimize what things are mono behaviors and only make things that really need to be a mono behavior actually be one now if you're coming from web development or business development you may be familiar with something like MVC and if you are just think of the mono behavior as a view it's just pretty interactive it may have some pretty good code in there to keep it interactive but generally it should be somewhat like a view now don't try to force yourself into that though so if you have a mono behavior and you need it to be a controller it's controlling some stuff totally fine just start thinking about actually separating out your code even if the logic stuff is all happening in a mono behavior or in multiple mono behaviors at least separate the things out so that you have the ones that act like of you and the ones that act like controllers but don't go overboard and obviously don't over complicate your project if you're building something simple like a flappy bird clone don't worry about it at all it's not a big deal this is more important when you're getting into real bigger projects another common mistake I see developers who come from a web or business background make is ignoring or under using prefabs they tend to build their own game objects and set everything up in code instead of pre defining these prefabs which is pretty much what they're there for and using them now if it feels weird because it's not in code you have to think of it a bit like a dependency injection system these prefabs are the packaged up objects that have all of the dependencies ready to go and you're just injecting them into your game at the right time by instantiating them of course it's not exactly like dependency injection but it's pretty close when it comes to a unity context so make sure that you're taking full advantage of these prefabs and especially with the new prefab systems in twenty eighteen point three we've got prefab variants and prefab hierarchies or nested prefabs so definitely go check those out if you haven't seen the videos I'll have them linked below so you can go learn all about those and see how much they can really help with your project now one mistake that I find is common across everybody is using the game object find options that are string based so you can see I've got an example here with ship equals game object dot find with tag and here people get tags they learn about tags and they start using tags to find all over their objects it kind of works but it is kind of slow process and it has another really bad side effect that it's hard to discover and it's hard to know when something's broken so I can have my code just like this somebody can go in and make a change to the ship maybe recreate the ship and forget to tag it as a ship and the game will stop working but I don't get any compiler errors they don't get any real notification that something is wrong there's probably the biggest reason that I don't like it on top of the fact that it's just a little bit slower to find with tag instead of caching these things and using find object of type now the game object dot find call is the same but even worse because here we're looking at the game objects actual name and game object names can change all the time somebody renames a prefab that instantiated object name might change somebody has some code that adds a little bit of debug info the object name changes somebody just renamed the object it changes and everything breaks again and the problem here is again you don't get compiler notifications you just sit there wondering what's wrong you have to debug in you're wasting time I mean a simple little thing like a tag missing could end up you know maybe take me five minutes it could end up taking somebody four hours or two days to try to figure it out before they finally realize oh it was a stupid tag somehow it got removed I don't know what happened now when we go on to talking about camera dot mein is the biggest offender and a lot of people have actually run into this issue and it's the same issue as with the ship it's just even more hidden so camera dot main calls camera four what is it game object out find with tag and it uses that main camera tag that's why when you create a new scene it has that main camera tag on it so if you add a new camera delete that old one you may have noticed say the project stopped working what's going on I can't see anything or I'm getting errors on all these camera main calls it's because it's using that tag underneath and it's I'd say hidden and secret although it's a pretty well-known secret if you're getting into unity or just kind of new with it it's a very easy to make that mistake in fact I have made it a million times now it doesn't make sense to talk about performance issues without talking about profiling the profiler used to be a pro only feature back in the unity four and five days but now it's free for everybody and you should definitely take advantage of it if you're going in there and just kind of guessing what you think is slow you're probably gonna be wrong and if you're coming from a standard programming experience you're probably really not gonna know what to look for generally things that cause big issues are just slow running code that's in an update loop probably at number one cause things like debug dot log calls in an update loop are actually really terrible so when you're profiling make sure that you're watching for those and disabling those when you really want to get a speed speed number there are a frame rate and also make sure that you do a build to your actual device when you want to get you real frame rate so back to the profiler though some other things you can do are look for garbage collector allocations and garbage collector calls you might not see it in here because we're really not doing anything but a lot of the time with a project you'll see big giant spikes and freezing or hitching now in a win web app or a Windows app you might be able to hide that and mask it and it might not be a big deal but in a game when your game freezes up for half a second it's huge it makes a big noticeable difference and it feels like there's something wrong if it freezes up longer than that obviously gets much worse and if it's a fast-paced game you're pretty much ruined your game just by in bad performance and having those little hitches those generally come from generating a bunch of garbage for the C sharp garbage collector or the CLR garbage collector to collect and clean up this happens by instantiating a bunch of objects that you don't necessarily need and then destroying them again that's why in games we generally like to pool things and reuse these objects so we'll create an object maybe deactivate it hide it away and then bring it back when we need another one of those say I've got ships that are destroyable I've never actually destroyed my ship I'll just kind of move it off the screen maybe change an animation or something and then bring it back to life when I need it because creating a new game object generates some garbage destroying it just means I have to garbage collect later so I want to avoid that at all costs well not all costs but at most costs now I also want to say that that doesn't mean you should never generate any garbage especially if you're getting started if you're just starting out with unity don't worry too much about it until it starts to become an issue now the reason for that is you don't want to kind of get derailed trying to figure this out while you're also trying to learn everything else but once you get to the point where you're getting like that that big spike that just went by that means you need to start worrying about this and you can actually click on this and let's see let's take a quick look if we expand out the player loop here and sort by GC allocation you can see what's actually generating that garbage and this 17 bytes may seem small and it really is but I got to remember that's per frame we're running hundreds of frames a second you know and this is a lot of bytes and it's slowly added up over a couple minutes and that's why it took a while before we got that that big spike now if we were doing a lot more this could be a lot faster and be an issue anyway when we're talking about performance just make sure that you profile don't guess now before we go any further I want to bring up a couple of the other systems that I see people commonly try to recreate and these include things like camera controls or camera systems so if you're building a game that's just got a relatively common or standard camera system or even a semi advanced one but not very custom you should definitely try out cinema sheen now if you have to really fine-tune it whatever but for most cases cinema Sheen works great at handling nice transitions does follow cameras and everything else really well so I highly recommend you check that out also if you want to build a tutorial the first time I did it I went through and scripted everything I made a special scripting system so our designer could go in and change things and adjust things and then well timeline got released and it kind of solves all of those problems now you can just build a tutorial with timeline let's take a little bit of time to get used to it but once you do you can do amazing things build up a whole system that's very visual and very easy for you to edit and change later and the last one I want to talk about is doozy UI so if you're building out a UI system for your game and maybe you want your buttons to wiggle and you want to do some fading and zooming all that kind of stuff again don't try to rebuild all that stuff from scratch just go in and grab doozy UI this one's the only one that's not free but it's definitely worth it and oh I almost forgot before I go any further if you're doing anything with text make sure that you're pulling in text mesh Pro not really a code issue but don't use the regular text use text much better performs better it's all around a better option now the next thing I want to talk about doesn't apply to everybody but a good number of people I know start to make a game they start to learn how to code or maybe they're learning how to code games and then they need some art and what they tend to do at least a good number of them is try to create that art on their own they start thinking like hey I'm a game maker now I need to make my own art and you know these guys made their own art in their own game that's what I should be doing it's really not if you're just starting out learning how to make games learning how to code and create games don't try to create your own art as well you're really trying to learn two things at once now if you're an artist already and these things come natural and it's very easy sure but for most people it's almost like you're trying to learn two different jobs or two different skill sets at the same time like if you're trying to create a new painting you wouldn't want to be creating the paints the paper and painting on there you want to do just the one thing be good at the one thing and then once you're good at that maybe consider working on something else but when you're starting out really just focus on learning how to make a game learning how to make it good and learning how to finish and that's probably the biggest thing make sure that you actually build your games out finish them and share them a lot of people will get started they'll make a couple little prototypes not really finish anything or they'll make a little game and never show anybody because they think it's not good enough it's not a whatever not fancy enough it's not Call of Duty nobody's gonna want to play it people will play it people would give you feedback and it's generally pretty positive and good feedback now if you're not sure where to post these games I like to just do WebGL games and build them out and put them on simmer die o or I'll build out a steam game and release it as a real project but in general if you want to just widely publish it shimmered io h dot io is another option not quite as easy to use from what I remember but still really good but whatever you do make sure that you are actually sharing your game this could just be putting it on to a mobile device publishing it up to the Google Play Store I think it's free it was free last time I looked very easy to do and get people playing your stuff it really motivates you to keep building more and you kind of learn from the experience when you see people play see that they do things a little different you'll learn in your games will get better and you'll be a better developer in the end anyway I hope this is at least a little bit helpful there are a whole bunch of other things that people do kind of wrong or mistakes that people make if you have some good ones that you have seen people struggle with before please just drop them down in a comment below I'll probably do a follow-up video on this with all of the things that I've forgotten and everybody reading will probably appreciate it as well also special thanks to everybody on patreon and all my email subscribers really appreciate you all all right thanks but you
Info
Channel: Jason Weimann
Views: 306,402
Rating: undefined out of 5
Keywords: unity mistakes, unity tips, unity for beginners, unity, unity vs unreal engine 4, unity tutorial, unity tips and tricks, #unitytips, u3d, unity free assets, unity beginner friendly, brackeys, unity3d college, how to make a game, unity best tips, unity 3d, c#, unity 2019.1, tutorial, basics, coding, beginners, making a game, unity 2018, game development, how to make a game in unity, tips and tricks, unity3d, gamedev, developer, game development unity, quill18, intermediate, unity tutorials
Id: 3kino_s-4mo
Channel Id: undefined
Length: 17min 31sec (1051 seconds)
Published: Mon Feb 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.