6 Useful Unity3D Things (one I just learned!)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I watched this on youtube and already knew all things in this video except the ground snapping. I always forget that.

However, no one speaks about the presets feature in unity and if I talk with someone about it they say always "wow, never heard about it". Why?
You can save all settings of components even entry ins project settings. You can even set this as default. So if you want example box collider always with isTrigger activated.. so you can set it by default. You can even move these presets new projects. Its actually very nice.

👍︎︎ 1 👤︎︎ u/MaZyGer 📅︎︎ Aug 18 2020 🗫︎ replies

I'm a big fan of Jason. He sometimes speaks a little bit too fast, but you can always rewind.

However, this is a guy that I frequently refer to for learning Best Practices, and I urge you to follow his YouTube channel.

👍︎︎ 1 👤︎︎ u/[deleted] 📅︎︎ Aug 17 2020 🗫︎ replies
Captions
a couple weeks ago i learned something new and i wanted to share that with you i actually learned this by having a discussion and a little bit of a debate with other unity developers where i was saying something and they were saying something completely different and i was wrong and this happens all the time right you got to remember that as a developer you're going to learn new things you're going to be wrong about things and you've got to be open to that and you really should be open to learning new things constantly for me this was a reminder and kind of got me motivated so i sent out an email to my list and asked for them to just send me things that i might not know teach me something new so today i'm gonna go over the thing that i learned and then a couple of the really cool tips and ideas that people sent in now if you watch through this and you have an idea for something else that you think i should have covered or you think everybody should know or that i should know drop a comment down below and let me know also if you don't mind please hit the like button and subscribe and share it really helps and i really appreciate it all right let's get started with the first thing what was that one thing that i learned about well it's actually just down to this single line of code and this is it this is that single line of code that led to a big debate and an entire youtube video this serialized list of game objects or a list of prefabs using a serialized field attribute and we were discussing and debating whether or not this would show up in the inspector now i was arguing against it saying you definitely can't serialize a list of game objects that'll never work you have to use an array so let's see if i was right jump over to unity and you can see right here in my gemsponder apparently you can serialize lists and this got added a long time ago i just got stuck with it in my head that you had to use an array all the time because that's how it was when you started and it just never really picked up and never clicked for me and the next thing that i want to talk about kind of follows along that same vein although this one i did know about and i was following really closely but a lot of people don't know exists and that's the c seven functionality in unity now i can blab on about what that means and how cool it is in fact i tried that and cut that out instead i'm just gonna go and show you exactly what these features are and what they mean really quick in just a couple of seconds so here's a spawner class and we're going to start with expression body properties and methods what are those and what do they mean well let's take a look at this property right here i have an update method checking to see if something is ready to spawn and here i have a simple property with a getter that returns whether or not the current time is greater than or equal to my next spawn time but this is a lot of extra noise and code for this one little line check here to see whether or not this time is met what we can do is convert this to an expression body property though hit alt enter into expression body property in writer or you can just type out the change on your own and you can see the converted syntax is quite a bit shorter and i think quite a bit easier to read now we just check to see if the time is greater than the time and we're going to return this value we're going to return whatever is after the little lambda operator here so what does that look like for a method an expression body method versus an expression body property well let's change this choose random prefab into an expression body method here i'll go hit alt enter oh got to go maybe onto the name of it and then hit alt enter and then choose expression body property and then you'll see that it looks exactly the same except that we have the parentheses so if you want to have parentheses and you want to generally if you want to pass in parameters to something or you want to do an action then you might you go with an expression body method over a property i'd say it just depends on which scenario you're in if it would normally be a property go with expression body property if it would normally be a method go with an expression body method let's go on to the next c sharp seven feature though and that's the null conditional operator it's question mark dot what is this doing and why is it here let's zoom in a bit here i've got a text object that's defined as a tmp text which is a text mesh pro text object this is the base class for it so that i can use it for world space and screen space objects and on this line i have a question mark before my call to set text now normally set text would just set the text of this object but this question mark here is saying hey first check to see if this thing is null if it's null then don't do it writer does give me a little bit of a warning here though in this underlined little yellow line and it's saying that this null conditional operator to actually check the life cycle of this object so if the text objects has been destroyed it was there and then it got destroyed we might get a failure here and throw an exception a no reference exception but if it was never assigned we're totally fine and if it's not a game object we're totally fine to use the null condition operator too i use it all the time i wouldn't worry too much about the lifetime check unless it's an object that you're actually destroying if it's something that you're creating and destroying at runtime then do a full null check let's go on to the next part though there's more to this line here and that's this dollar sign and the quotes with the variable in here this is the string interpolation feature if you add a dollar sign before quotation marks you can put any variable inside of here just by putting in the little braces and saying something like next spawn time adding in the closing brace and it'll put in your variables right into your text and makes it nice and easy to read next i want to talk about something that a lot of people know a little bit about but probably not quite enough about and i got a couple recommendations on this one and this is co-routines the first part about co-routines that people don't generally know is that you can start them off in your start method you can actually make your start method an ienumerator and then just do a yield return in there and it will actually kick it off as a co-routine and wait you can see here i've set up a simple little delay that waits for one second and writes a message without having to start up a co routine or add an extra code now let's talk about keeping a co-routine reference i have this co routine right here on line six private co-routine co-routine why do i have that and what would i use it for well we can actually manage the life cycle of our co routines by keeping a reference to them and here i've got a wait a minute method and an update method let's take a look at how this would work and how we would use it so i've got my update method set up so that i can hit the alpha one key or just one on my keyboard and it will first check to see if this co routine is not null so if i've assigned something to this co routine i can stop it by calling stop co routine and just passing in the reference to the co routine now you might wonder where do i get the reference so it's on this next line right here line 31 when we start a co routine we can get back a reference to that and cache it in a variable then i can use it in my stop method to kill it whenever i want so here on one i stop the routine and then restart it and wait a minute and here if i hit number two i just stopped my co-routine it's important to note though that if i don't stop it here and i just start another one i will lose the reference to the first one but it won't stop it's not going to kill itself just because i started another co-routine so i want to make sure to manage these things intelligently when i'm managing them but it's important to know that we can and it's pretty powerful thing to do let's see what that looks like in the editor real quick so i hit play and then there's my delayed message and if i hit one i should see my messages start and let's uncheck collapse and i'll hit one again and you'll see that my messages restart down there at the bottom and it should start scrolling and if i hit two my messages completely stop so there you go cool co-routine functionality next we'll hit some hotkeys that most people don't know about and have saved me a lot of time the first one is just for controlling where my camera is see how my camera matches with my game view right now if i want to move my camera over to here and get a better view i can go get my scene view in position with that right mouse button in wasd but then go select my camera and hit ctrl shift f this will move the object to match the scene view's rotation and position this doesn't just work on cameras i can move another object like go grab this cube right here and move down here and hit ctrl shift f and you can see it moved and matched my orientation most of the time though i just use this for cameras what do i use for moving objects around are there a couple other things first let's move this player around with ctrl shift watch what that does it snaps him down to whatever object i put him on so he's kind of snapping to ground remember that's just ctrl shift and you'll get that little box and drag around another really cool one is vertex snapping i'm going to select this cube right here this little one and then hit v now when i hit v notice that i get a box here i get a box in each of these corners and just one in the center there these boxes are actually for the vertices of my object because it's a cube there aren't very many but let me grab this bottom vertex and i'm going to snap it to this top vertex of this other one so i'll hold v click drag and snap it up there and now it's aligned perfectly i don't have to do the math i don't have to figure out the values or anything it just snaps the vertexes together the last hotkey i want to share solves a problem that i see a lot of people struggle with and that's that they hit play and their scene view goes away the game view pops up to the front now you could just drag your game view out make it a separate tab or put it on another monitor but if you don't have that option you can also hit shift and space over the scene view to maximize it then when you hit play it won't switch over to that game view and it'll leave your scene view up so you can see things now i'm going to show you a really cool trick for debugging uis that don't work here i've got a button that i can't click on when i click on button one button two gets clicked on if i click over here it works but in the middle it's broken oh there we go broke it again so how would i debug this before i would have gone around writing some extra logs or trying to figure out what object is selected or doing some weird stuff in code maybe there's actually a very simple solution for this if we select the event system in our scene hierarchy we'll get a little debug view here in our inspector now this might be collapsed if it is just click on that little thing right there and it'll pop right up and what you want to look at is the pointer enter watch what happens as i enter things here i've entered a button and you can see oh that says something about a bad image that's interesting but here if i click on it everything's okay and here when i click the button is fine and here it says the last pointer enter was that text but if i go to the middle i am getting that bad image again so now i can expand it out and realize oh hey look i actually have this image here let's see where that is if i hit scene view and go to my bad image and then hit t to hit my transform tool or my rect transform tool i can see this actually overlays into here now the event system debugger shows you a lot of other stuff like what things you clicked on how much your mouse moved and everything else so i highly recommend that you get familiar with it and just get used to the idea of checking it whenever you have an issue with your event system there's one more really cool thing in the game view that i wanted to show though and this is something that's super simple but helps a ton and that's this mute audio button if you've ever been overwhelmed with extreme noise you're playing your game and constant just power-ups or coins getting picked up or you just get tired of hearing the same background music over and over and over mute audio button will turn everything off but while we're on to mute audio a lot of people know about this one a lot of people don't know that unity actually has an entire audio mixer system built right in if you go to window and mixers you can set up an entire mixer create a mixer create channels adjust the levels and the sound effects of all of those things it's cool to play with and definitely something worth checking out the last tip i want to show is something that i think applies to all of us and it's something that i use on a really regular basis and that's the debug view of the inspector if you have your inspector window selected you can click on the three dots and go to debug and suddenly your custom inspectors will disappear your sprite renderer might look like a mess like that but you'll also see a bunch of other new fields like my total spawn that's a private field on this gem spawner and my next spawn time i wouldn't normally be able to see those and i'd have to write out some sort of a log or make a public version of them the debug view gives me quick insight into what's going on there and lets me well really just debug things without having to write any extra code now what if you don't want to keep switching back and forth between normal and debug one cool thing that you can do is open up a debug inspector and then hit add tab and just add another inspector and have a debug and a regular inspector side by side or that i can tab back and forth between i had a ton of submissions when i sent out a request for ideas so i wanted to at least thank everybody who replied and gave me good ideas i couldn't fit them all into this video but i plan on doing quite a few more and i also want to say thanks in advance to anybody who's put a comment down below with ideas or suggestions or tips or things that you think that other people just don't know and if you got one feel free to just put it down there now now's a good time for it also again special thanks to everybody on patreon really appreciate you and um yeah please share like thumbs up all that stuff thanks again have fun coding bye
Info
Channel: Jason Weimann
Views: 75,666
Rating: undefined out of 5
Keywords: game dev, unity 3d, game development, unity technologies, serializefield, list, coroutine, ienumerator, null conditional, expression body property, string interpolation, vertex snapping, eventsystem, audio, mute audio, unity ui, unity eventsystem, unity3d, unity, brackeys, code moneky, sykoo, devlog, c#, c# 7, learn unity, gamedev, unity tutorial, unity beginner tutorial, unity for beginners, unity game dev, unity game development tutorial, game dev log, video game industry, game
Id: KRq0-0KY6bU
Channel Id: undefined
Length: 12min 30sec (750 seconds)
Published: Sun Aug 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.