A BETTER way to setup new unity projects!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Found this super helpful. He's been on Jason Weimann's podcast for awhile but just started his own youtube page. I agree with his general philosophy on dev stuff, and I've learned a lot. Hoping he keeps making these !

👍︎︎ 3 👤︎︎ u/cfinger 📅︎︎ Sep 21 2021 🗫︎ replies
Captions
so jason here and i have been currently sorting out my computer whenever i finish a big project i wipe the machine start from scratch it's pretty easy when everything is mostly cloud-based these days um but i was doing that and i suddenly stopped and thought rather than automate everything back to normal it's probably a good teachable moment to stop and explain why i set things up the way i do so let's go through and have a look at the way my computer is currently configured so as for apps i'm mostly developing unity and i use writer for my editor so they are predominantly front and center i also make good use of windows multiple desktops so you'll see here this is where i would normally be working in unity but i also have my writer on a different desktop which we'll get to in a minute and then i have my project management slash organization stuff on another tab in this case i'm using a combination of obsidian and amazing marvin we won't get into that now that's a whole other conversation to have first let's look at my folder structure so my pc again very minimal i just have my normal c drive and then a storage drive storage drive is mostly used to contain whatever tv shows or movies i'm watching as well as any inbox for downloaded files things to process and organize and then what you're seeing here whatever video capture i'm currently doing it's much easier to store there and then as well as that on our quick access it's basically just the standard documents downloads whatever and i try to keep those clean i try to keep i empty them out daily that way there's not too much stuff that kind of piles up and makes the computer messy now the important one is documents so in documents i hide every folder that i'm not using so normally most apps and this actually goes for the the pc menu as well so you'll notice here windows is very limited here and then into the project directory it's just the apps that i actually care about user install anyway so back on track let's go to the documents directory and this is all i have i have overwatch because i play far too much overwatch i have my unity projects and then i have something called a vault which is just the place that this obsidian layout is storage again not super important right now just something to note so two projects this one unity projects folder that's where i store everything and we're going to make a new project now and have a look at the way i approach it so unity hub new project and we will put them into our unity projects directory and i will call it u dot um new project example now first thing to note u dot why do i use u dot as a prefix well while unity creates this for us we can have a look at why i do that one of the icons in my taskbar here is something called everything quite nice to have and what this does is it is an indexer for your operating system and this lets you find everything now right now it's going a bit crazy because it's literally creating all of these folders for that new project as you can see but the main thing to note about it is i can find anything on my computer so if i go to switch to everything and i type in star.cs this shows me every c sharp file on my computer and if i was looking for that a screen fader that i was working on i'm sure there we go screen fader it's in that project under that directory this makes it very easy to find things as well as directories too so now if i go back to search and i go to folder if i type u dot i can pretty clearly see every single unity project on my machine and that's the main reason i use the u.prefix because unlike solutions in net or other applications that tend to have their own application file there's nothing that really identifies unity project as a unity project except the folder structure and there's no kind of nice way to search by that but if i use udot as a prefix i know for certain that that is in fact a unity folder and it's very easy for me to find and reference so we have unity open now and first thing i like to do is delete everything i don't even want that default scene get rid of it uh yeah we're not even gonna save this one we're gonna have a blank nothing so we have no assets in our project now the way i normally start a new project is i go through the structure of creating the folders that i use in every project in my case this is a new folder called underscore project because the underscore will put it at the top so as i install new assets they are placed below mine rather than it kind of hiding my own scripts in the middle of everything and then at the start of a project i tend to stick with the standard by type definition so scripts and art so i normally start this way and then later on as the project gets bigger i switch to a feature based structure but if project small you might as well start with the simplest thing that works and this works now that being said i don't like having to write that out every time there is a default set of things i do in every project that i don't really want to have to copy in myself so now we're back to a completely empty unity project so we don't want to have to put those folders in every time ourselves if we're going to use them in pretty much every project it would be nice to automate that process a little so what we're going to do is we're going to make a really quick editor tool to help ourselves so if we create a new folder called editor and inside of here we create a new script and actually before we do that let me point out something real quick so if i go up to my project settings so this is important to set and what this will do is it'll kind of group every script that you make for this project under the same name now i've talked before about why this is valuable let's just take my word for it for now just set it to something like your name now if i go to create a script what it's going to do is it's going to use a template so i will start by saying tools menu now this script is going to look a certain way and if i bring up writer this is probably not what your default template looks like because i've customized mine so let's have a look at how i did that and why i did that so if i go over to my uh let's see templates replacing the new amount of behavior template so in this directory here there is a text file now there's one for each template that is the default that unity will create for you so script dash something new timeline new behavior etc in this case the one i use the most new behavior script and the default template has the start to the update and a bunch of comments and other stuff i don't really care about so what i do instead is i create my own it's an awake and a empty section with the name space wrapped around it and if we look at what it gave me that's what it gave me so in this case that's actually not what we want but the point is that it did follow that template so we're going to get rid of the awake we're going to get rid of the mono behavior we're going to make this static and we're going to give it one static function and we're going to call it create default folders now in unity there is a menu item that you can put on top of a function that will make it show up in the editor so in our case we're going to want tools setup maybe and then we will say create default folders now if i save that and head back over here you might notice up here there's now a new tools menu with a new setup function with a new create default folders so we've got ourselves a way to write code that will run effectively for the editor let's have a look at what our options are here we can get rid of that using statement we're not using and to begin with we basically want to make a directory so we have to first of all get the directory we're currently in i can log the application data path and i hit our menu item you'll see it drops us in the assets directory which is perfect because that's where we want to be we want to start putting scripts or folders to start with inside of this directory um directory create directory and then you choose the path to create the directory in our case we want to start here so the best way to do that is path dot combine and we're going to combine the application data path with whatever our new directory is in our case we'll start simple and we'll make our project folder clear that log and last but not least that won't actually show up initially because it's not going to reset the asset database until you refresh the asset database we just have an editor folder but if i click tools set up create default folders there we go we now have our underscore project so what we'll do is we'll get rid of all of these static functions so we're using path application directory asset database that's a lot of static functions all in one place that kind of muddies up the code so you can actually do is you can using a static version of something you can directly reference it so if we reference uh where is system systemdirectorysystem.io.directory directory and if you notice by using its static up here it grays it out down here so what i can do is remove it from here i can now do the same thing with the others create directory combine the data path with project and refresh pretty straightforward now um i want to create a number of directories not just the one so we're going to encapsulate this function so we're going to say create directories and i like to have a root directory and then from the root i like to pass in a collection of directories that we're going to make from there so and this needs to be static we're going to be referencing in a static context so now what we can do is take our path that we've got here and we'll combine it effectively so i will say this will be our um full path and that's going to be if we combine the data path with the root and then for each in the directory list new directory we can say directory and we will combine our full path with our new directory and yeah that seems fine to me so now we can start to create a couple of directories so let's create you know what in this small context i think yeah let's simplify it further i can i can read it from here if it was a longer method i would change it but this works fine so in the project directory we want to create um scripts we want to create art and we want to create scenes tools setup default folders we have underscore project art scenes and scripts cool we now have a helper function that lets us create whatever the default folder setup we want is the only problem is this currently lives in this project which kind of defeats the point we kind of want this to live in a way that we can access across any project we want that's not too hard to do so first let's re-delete them and let's head over to our our editor folder here and the first thing i'm going to do is give this section of code some sort of name and we do that with an assembly definition so let's head on over to assembly definition and we're going to call this jsonstory.tools and now we have this folder and what we're going to do is we're going to make a package out of it so let's pop back over to our directory structure here and we've got unity projects if we make another folder and we call it unity packages we can then make a package that contains this stuff in it in this case tools new folder tools and then we need to give this package a kind of definition and the way you do that is with a package.json file that's pretty small don't worry it's not too crazy so if we do package.json and we can open this up in vs code i have a small snippet here and as you can see it's really straightforward it's just a name a version and a display name this is what will show up in the package manager when we try to access this package so now we have a folder with a package.json that we can put code into so the way we do that is we can head back over to unity and we can have a look at our directory here and if we go in and just pick that whole chunk of code here so we have our assembly definition the meta files and the directory and if we cut that and we head back over to our tools folder we can now paste that in here we now have an empty project again and we've lost our tools menu because there is nothing in this project now if we want to bring all of that stuff in we can go to windows package manager and then add package from disk and we can click on so just to show you where it is documents youtube packages tools and just double click this package json and what unity will do is it'll bring it in now you can add your description you can add your details you can even add sample projects in here too um that's really cool but we'll get to that later all that really matters is we now have a custom package that brings that code in and so just by including this our tools menu menus back and so even though we have no code in our project it's a completely empty project we can say hey let's click tools setup create default folders and there we go we now have a way on a brand new project to configure it whatever way we like and what's cool is if you look under packages you can actually see all the packages that is installed in your machine or at least for this project and then under the one you've just made is the editor folder and we can go in and edit this if we found that useful that basically outlines how i share code between multiple projects and how i use unity packages relative to multiple different clients the other thing worth noting there is i briefly touched on marvin and obsidian and some of the other tools i use if you want me to do a deep dive in the way i use them let me know in the comments below if you found that helpful feel free to like and subscribe and you can also catch updates on what i'm currently working on on my kofi page which is linked in the description have a good
Info
Channel: Jason Storey
Views: 7,265
Rating: undefined out of 5
Keywords: Unity3d, Beginner, project, game development, gamedev, game engine, Unity, How To
Id: nVieP57TD20
Channel Id: undefined
Length: 15min 43sec (943 seconds)
Published: Sun Aug 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.