10 Unity Tips You (Probably) Didn't Know About

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome I'm Brandon and here are 10 tips that you probably didn't know that you could do in unity the default setting for a new scene is to sort the transparency on the z-axis that means that if we have two Sprites that are on the same layer the engine will use the z-axis to determine which object to render first this makes a lot of sense for a 3D game but for some 2D games it really doesn't for example in my game which has a top down perspective I want the player behind this statue when he's higher on the y- AIS and in front of the statue when he's low on the Y AIS cuz this just looks weird we don't even have to do any coding to accomplish this all we have to do is change this to custom axis and make sure one is on the Y and there we go sometimes you're going to want to update the name of your variables but where it gets annoying to do that is if you had a serialized or public variable where the value is being set in the inspector what happens is as soon as you rename the variable the inspector setting is reset to whatever it is in the code which can be a real nightmare if you had a whole bunch of values or settings that were tweaked perfectly now they're gone references will be blank layer masks will go back to nothing and it can be a real headache so let's take this back to what it was for a second you'll need the unity engine. serialization namespace but then you can use the formally serialized as attribute and plug in a string for your current variable name then change the name to what you want them to be now you can see we updated the names but we kept all of our references now we can just go back in and remove all of this code to stay organized sometimes you might just want all your references in one spot or you might want to make them collapsible in the inspector your inspector can start to get really messy really fast when you have all kinds of references to audio clips and prefabs and other things like that something we can do is create a separate class inside our main class and add system. serializable at the top and then create a variable for it up here now we have a nice collapsible group in the inspector and when we want to reference it in code since I called mine sounds we'll just call player. sounds do whatever sound we're looking for which to me just seems a lot more intuitive anyways sometimes it can be really useful to control the priority of what gets selected when you click on it in the editor for example in this scene I have a grid with a whole bunch of squares but this grid is actually split up into four different chunks what I want is to select a chunk when I click it not an individual Square another example here with my player it's really annoying that when I click him it selects one of his child objects instead so to correct that you can add the selection base attribute at the top of your script so now you can see with my grid it selects a chunk first and then if I click it again it chooses an individual square and over here on my player I click him and yep it selects him then if I click it again it selects his weapon in unity it's very common to be using fields in the inspector to set your text but what do you do when you need need to have variables referenced in this field here to show things like attack power for example I've made some pretty weird and complex methods to get around this in the past and I wish that I'd known about the set text method so what we can do is instead of setting the text directly like this we can use the set text method set text has many useful overload methods but for this use case we can use it to pass in float variables and how we pass in the index is we wrap the index in curly brackets so 0 is the first argument one is the second and so on so you can see here we're passing in two variables on each card and then to format these let's say that on the first value we want no decimal showing and on the second value we want two decimal places showing we format it like this and there you go all right since we're here dealing with text and numbers and whatnot we might as well answer the question how do we color only certain characters or bold them or things like that textmesh Pro supports what are called Rich Text tags and I'll leave a link to this down below in the description I went ahead and added a color variable to my scriptable object just so I can easily grab the heximal value and I'll make my current values bold and red okay now I'll make my new values bold and green and there you go it's easy to ignore these three tabs here in Visual Studio especially when you're self-taught like I am and you came into Unity knowing almost nothing about Visual Studio you're probably not going to touch these first two very often but the third one here is actually really useful it lists all variables and methods in your current script so if I wanted to find my jump function in here you can just click it type jump hit enter and it will jump right to that function with any game engine you're using it's important to know the order of execution so that you understand the order that your code runs in and sometimes you will run into situations where you want certain scripts to be loaded before others and that's where the script execution or order comes in handy if you go to edit project settings script execution order you can add any script you want in here and move it around as you see fit all scripts by default execute at the default time so if you want anything to run before that put it in before and if you want it to run after put it in after you can actually accomplish the same thing with the default execution order attribute as well zero is the default value so make it negative if you want your scripts to run sooner and positive if you want it to run after the default sometimes even even when you have really well-named variables it can still be really useful to be able to leave your future self a note to explain more details and things like that and for that you can use the tool tip attribute once you've put this in there just highlight over top of your variable in the inspector to see a little text box pop up C supports something called overload methods this means that yes it's true we can't have two methods that share the same name unless those methods have different arguments a good example of this is the instantiate method you can spawn an object with nothing but the game object as an argument or you can pass in positions parents rotations Etc so when we go to call this spawn object method for example it'll decide which one it's going to call based on which arguments we pass in when we call it if I pass in nothing it's calling this one if I pass in a vector three it's calling this one and if I pass in a vector three and a transform it's calling this one you can create as many overload methods as you need to so long as they all have different arguments like the video if you liked and if you have any more tips for Unity or for visual studio leave them down below in the comments thank you so much for watching bye I'd like to give a very special thank you to all of our Hall of Fame patrons yakob yondu Christopher Nichols zandre Kesler fonan weade brain wav binary couch KB at btech games and Ian oral as well as our Early Access patrons Ken weight Mason Crow liquid EG Alexander prus Jude Greaves Felipe gasos Santos obber Francesco Lata Bill guo alone on Mars Alex fredman Danny rlif Neil Ben kerger merler Sam maxar Ming Tong Tran and Mauri Ula if you choose to support us on patreon you can get early access to all of our YouTube videos monthly Alpha builds and more
Info
Channel: Sasquatch B Studios
Views: 6,899
Rating: undefined out of 5
Keywords: unity, unity2d, unity tutorial, sasquatch b, unity beginner tutorial, game development, unity tips, unity tricks, unity tips and tricks, unity tips and tricks 2023, unity tips for beginners, unity pro tips, unity hacks, unity best practices, game dev tips, unity save time, unity easy tricks, unity best tips, pro tips, unity beginner advice, unity things to know, unity things you didn't know you could do, unity hidden features, unity tips and tricks 2024
Id: JgAhIX8YLBw
Channel Id: undefined
Length: 7min 8sec (428 seconds)
Published: Thu Dec 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.