Subnautica Style Base Building with Saving and Loading in Unity | 3 HOUR GAME DEV TUTORIAL COURSE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the first building tutorial video in this video it's just going to be about the setup and getting the basics kind of outlined for an idea of what we are looking to create you can see here we've got our um I've got my test project here I can come over here and we can hit um tab we can choose from one of these parts and I'm going to pick this uh base piece here and we can place that down we place another one down maybe put a corridor down that into place and and you can see here is our base and oh I've uh got the gravity turned down so I can get so I could jump over stuff um you see here we can enter our base come out the other side and then we can come here we can save our base and if we exit out of the game and go back in then we load our base you can see here is our base that we've just saved so you can see that we've got saving and loading of the bases working too and we've got quite a few different pieces that we can rotate and snap into place so here's like a bit of an observatory piece so yeah um if you want these uh fbx files of these base Parts uh they are going to be available for free over on my patreon uh you'll find a link in the description below for those so you can download them and follow along and if you are a paid supporter on the patreon you will of course get access to all of the actual project files and all the scripts uh that we create together as well so let's just get stuck straight into this so I'm going to create a new project I am using Unity Hub 3.2 um we're going to build this in 202.3673 to start with and we can read more about this here uh so it's a preconfigured character controller for first person it uses uh the universal render Pipeline and it comes with uh a range of packages pre-downloaded such as cinem machine the new input system uh render pipeline text M Pro Etc I'm going to choose a location for this I'm going to go to my f Drive Unity Unity projects let's place it in here and I'm going to call this the build tutorial series and I'm just going to create a project okay so here we are in the uh project you can see there is a read me in the file you want to learn a bit more about the first person template um but for now what I'm going to do is I'm going to select the read me starter asset PDF the license uh tutorial info and mobile and we'll just hit delete we don't need them and we'll let this reload and then I'm going to go over to my preferred layout which on my 4K screen is having the hierarchy down here and the console down here that gives us a lot more space to work with in the actual uh main view here so in this video we're just going to be uh creating a build tool. CS script um this will be the build tool that we used to interact with the world and actually um put the logic onto for building stuff and by the end of this video we are going to just have some cubes spawning in the world so let's create a folder to keep organized so I'm going to create a folder we'll call this um build system script and then in here we're going to create a new script and we're going to call it uh build tool and we'll open this up uh I'm using ryer as my IDE um you'll probably be using visual studio that's fine and let's zoom in here so we can see all of this okay so let's create the variables for our raycast that we are going to do uh to decide where we're actually going to place stuff in the world so I'm going to make a serialized field I'll do a private float which I'm going to call underscore uh Ray distance I'm going to have a serialized field private layer mask and we'll call this the build mode layer mask and I'm just going to duplicate this and we'll call this the delete mode layer mask which we'll use when we are building and deleting objects from the world and then we'll want a serialized field private int we'll call this um default layer int and this is going to be later on when we um spawning buildings into the world we can assign which uh layer we want them to be on for the physics interaction and I'm just going to default this to eight but we'll be to change it in the inspector then we also need a serialized field private transform and call this Ray origin and then when we are building or deleting something uh before we place it down you'll see that we had a different material showing um so we want to have a reference to those materials so I'm going to do a serialized field private material I'm going to call this um building mat positive and building mattive okay so we're going to be able to edit all these in the inspectors and then we're going to need um some other private variables that we don't need to kind of edit in the inspector I'm going to do private Bull and P this delete mode and this is just going to let us um flag whether we are wanting to place an object or delete an existing object in the world we then need a reference to our camera cuz we're going to be using it a lot so we may as well uh cach it in start so we can say um for camera and we can do that in our start method so void start camera equals camera. Main and with all of that done we can start working on our update method so here we want to do a raycast into the world and get the position um that will looking at in the world and then we can position our spawned object at that location and we're going to do that by creating a new aray uh which will start at our Ray origin position and then going in the direction of our camera's forward Direction and then we can see if anything hits the layer mask we have chosen if it is we can position the building preview by setting its position to that uh but for now we'll set it to the direct position and later we will get it so the position snaps to a grid so I'm going to wrap that logic in a method that's going to return a ball um and we can say is Ray hitting something this is going to take in layer mask call this layer mask and it's going to pass back out a raycast hit which hit info so like I said we'll construct a new array so I'm going to say bar Ray and set this equal to a new Ray and it's going to start at our Ray origin do the direction it's going to go is our camera do um transform do forward Times by The Ray distance what we've going to set in the inspector then we can turn physics. raycast and we pass in the ray just created the hit info out parameter the ray distance and the layer mask passed in here we need to say out hit info so this will tell us if we are hitting something at the given layer mask and it's going to pass back out the thing that we are hitting and if it is hitting something then we'll be able to position our building preview by setting the position as I said and eventually we will snap it to a grid and then eventually when we're happy with our position we can press the left Mouse button to actually place the um object so just to test this is all working I'm going to say private game object and we say um game object to position and this is just going to be a test variable we'll change this later um but what we want to do is we can say if game object to position is null then we just want to return and if it isn't null we can set um so if it's null or we we are not hitting something this is on the uh build mode layer mask do out Ray cast hit hit info so if we don't have an object to position and we're not hitting something then we're just going to return out of our update function but if we are hitting something but if we are hitting something then we can say game object to position is equal equal to our hit info. point sry game object. transform.position is equal to hit info. point and say if mouse. current. left button was pressed the frame then we're going to instantiate the game object to position at the HIIT info. point we can say HIIT info. point uh and do Quan do identity so let's go back over to Unity and check this working so let's jump over here we'll have to let that pile just going to create uh delete those two red items add and add back in a UI system click replace system module and I'm going to go over to our main camera into this I'm going to right click uh 3D object and to the camera I'm going to create an empty and I'm going to call this our build tool I'm going to add our build tool script to this I'm just going to position it somewhere out in front of our camera I'm going to make a cube underneath it scale this down just so we've got a sort of Vis visual representation we can see that our build tool is there in this camera window we can actually down a bit down look back down bit more so there we go that's our um build tool and then I'm going to add another empty to this I'm going to position it out at the front of our build tool so this is the ray origin position so I think that will do call this the ray origin and I've just jump I've just restarted my Editor to make the UI a bit bigger uh for the recording so people can see a little bit better what's going on so I'm going to now go to our main camera to the build tool and we need to set this up so for the ray origin and drag in this empty that we've made and we're going to need to make some uh layer masks here so we can um what I'm going to do is I'm going to click the Flor make sure that we've got this for mesh and I'm going to go to our layer here and I'm going to select round is our default layer and I'm going to select this bigger uh piece here this big blue bit and I'm going to set that to the ground as well and we're going to go back over to our build tool for our build mode layer mask we're going to just select ground for the um Ray distance I'm going to set I'm going to set that to 12 so that'll be um it'll shoot array 12 distance 12 units out in front which should be about 12 M um and if not it'll just place the kind of sky in front of us uh eventually and then let's make a cube 3d object Cube going to position that 0 move forward so again this is just temporary we're going to be spawning in our buildings uh through code but on our build tool we can drag this cube in to uh oh I haven't made it public private so we'll do public game object and we'll go back over to Unity then we'll drag in our Cube our game object position now if we hit play that should theoretically work so let's hit play okay so you can see that is working we are positioning our Uh something's going on with our character but we can click the left button and spawn these cubes into the world okay so that's working we've got this weird bug where we are being pushed back um but we can click these uh the left Mouse button and place these blocks uh the reason for this weird surfing issue is that we've got a collider on the cube of our build tool if we disable that uh glider you see that we don't have that issue anymore so we can click and we can spawn in our um cubes we need to make sure we do that not in play mode we've got our turned our box collider off you can just delete the collider actually and but you can see now that we can spawn as many cubes into the world as we want okay so now how about we try to be able to delete the cubes out of world so back in our update method uh we're going to listen out for a key press and I'm going to do the q key so we can say if keyboard. current. q key was pressed to this F frame and we're going to set delete mode enabled to the opposite itself so we equals whatever the opposite is so if it's true it'll set it to false it's false it will set it to true and then depending of uh on if delete mode is enabled or not we're going to do different logic so I'm going to uh take this code cut it put it down here in a private void build mode logic function do the same make a new private void and we'll say uh Delete logic and then up here we can now say if delete mode is enabled we will do the delete mode logic else we will do our build mode logic so again we want to see if we are hitting um something if we're looking at something and we want to see if we're looking at a building and if we are we want to delete that building from the world so we can say if uh not is Ray hitting something and we're going to pass in our Elite mode layer mask get a out raycast hit hit info so if we're not hitting anything we're just going to return if we are we going to listen out for the left Mouse button so we can again so we can say if mouse. current. left button was press this Frame then we're going to delete uh going to destroy our HIIT info. collider do game object now we'll need to do a bit of um brickery and just second but I'm going to click this Cube first I'm going to add a new layer to it going to add a building layer mask on layer 10 we going to set our Cube to be of layer building select that there now back on our build tool we can go over to our delete mode layer mask and choose building we can place a few of these um around going to go back to our build tool and I'm just going to remove the reference to the cube that we are positioning and then I'm going to come up to inspector here and I'm going to swap over to debug mode so I can check this delete mode enabled toggle um so if I press play oh hang on got a issue here okay that's because of this or check so what we want to do is can take out um this hit info uh section so we're saying if the game object to position is null then we'll return and we'll do separately if we are hitting not hitting something we'll return and then if it eventually gets past this then we know it's safe to use our game object to position let's go back over to Unity and that should clear up this issue we're having here in the console so we hit play instead of is null I'm going to say equal equal null head back over to Unity and see if that is that's fixed it okay so I've done um equals null um and then so you can see here we're in the world and we're pointing around let's head over to our build tool you see that we've got this delete mode enabled toggle so if I press Q you can see that's toggling off and on now it's really hard to see what we're pointing at but if uh Delete mode is enabled and we go over here and we're looking kind of at this Cube and then we left click see that we can now delete this uh object from the world and if we um googgle uh Delete mode and then we set this Cube to be then if we set this Cube that's left as our game object to position and we go back you can see that we are now positioning it and we can spawn that in and if we toggle back delete mode deleting stuff oh I think that's a good ground ground work for this video I think that's a good place uh to leave this video in the next video we're going to be looking at changing the material of the place objects uh depending on if we can place them or not um or if we're trying to delete them so we'll turn them red if we're looking at them and we want to delete them and we'll also get the object placement snapping um to a world grid that we can Define so that's going to be in the next video if you want the project files as I said they're available over on patreon as is the full series of these videos they're all recorded and uploaded and available over on patreon.com dampas but if you can't or just don't want to support on patreon perfectly fine I'll be uploading the rest of this series kind of on a weekly basis going forward uh here on YouTube and as I said the free kind of models of the rooms that we'll be using uh they are available over on patreon you don't have to support that that's will be just a public post um so feel free to head over to the link in the description to grab those uh models you can follow along in the meantime time thanks for watching and I'll see you in the next one bye I'd just like to take a minute to thank my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP tier we have John SM and Trey Briggs and all of the wonderful 4,000 XP tier members are on screen now thanks again for your support hello and welcome to part two of the build system Series in today's video we're going to be working on getting the material of our objects to update based on a few different conditions as well as getting them to snap to a grid as we place them in the world so let's get started so the first thing we need to do is we need to make a building script so let's go over to our scripts our build system scripts folder and we'll right click create a new script call it building and we can open this up so in this script we're going to need to do a few different things so we want to get a reference to our renderer in in this case it's going to be the renderer of our Cube object um and that's so we can set stuff like its material so we'll say private renderer call this UND renderer and we also want to make a reference to our default material so the one that we start with so we can say underscore default sorry private material and say underscore default material now in our start function we are going to with our renderer we say renderer equals get component in children and turn our renderer then we can say the material then we can say if renderer so if it's not null and we found one then we can set our default material equal to our renderer dog to our renderer material and then we want to make a public click void update material function which is going to take in a reference to a material so I'm going to say material new so here we're going to say if the renderer do material is not equal to new material then let's set the material to new material and we also want a public void uh method called Place building and call this when we are you know placing the building and we can say renderer do material is equal to default material like that and we can also create a private pool up here going to call this flagged for delete this will handle changing the material based on if we pointing at this object and we have said that we tend to possibly delete it so we can say public void um flag for delete this will take in a material call this material and we can call our update material function passing in that delete mat and we can set flagged for delete equals through I'm just going to pull get rid of that capital F and put underscore F keep our nameing convention correct then I'm also going to make a public pool called flagged for delete which is going to be a getter for our flagged for delete ball so flagged for delete and in our place building method here uh we're kind of doing what it says here so let's just call our update material function and pass default material and here we are going to do a public void uh remove delete flag which doesn't need to take in any parameters that's going to update material back to our default material and set the flagged for delete B back to false so now let's head back over to our build tool. CS function we've got our build mode logic here this is going to be how we can change the uh game object to position we can change its material based on whether we're hitting something or not so whether we're looking at a valid build spot and and to do that instead of getting a reference to a game object called game object to position going to swap this over to be a building reference and I'm going to rename this variable to spawned building pop this over to serialized field private so we can set it in ins Spectre but we're starting to get a bit stricter now with our code because we're going to use this now throughout um we don't want to be able to change this kind of outside of the code base um again for now we are going to set it in the inspector but eventually we'll be spawning this building in through UI and what we can do is in our build mode logic so if it's null we are returning that's fine and here we're saying if the ray isn't hitting something then we're just going to return but instead what we want to do is we actually want to do something if we have a building but it's not hit something what we want to do is call spawn building do update material and we can pass in um the delete material Building Material negative and if we are hitting else we're going to set the building's position to the HIIT info. point and we are going to call spawned building dot material State material and we can pass in the building material positive then here with our left Mouse button uh pressed frame and save a reference to this building that we're instantiating so we can say building call this placed building we'll set that equal to this instantiation so we're going to spawn into the world and store a temporary reference to it then we can say placed building do Place building and that's going to currently all that's going to do is update his m material to the default material if it's not already set to that let's confirm this is working before we go and handle the delete mode logic because that's um a little bit more involved so let's go back over to Unity make sure we're all saved now I'm going to go to this cubes that I've made and I'm going to get rid of them all apart from one and to this I'm going to right click create empty parent and I'm going to rename this build building let's add our building script to this empty and then now this is going to look in its children for a renderer so it's going to find this Cube it's going to get the mesh renderer and then that's how we can change the material of Cube and over in build tool going to drag in our building reference and again we'll do this all through UI we won't actually be spawning these in dynamically but for now we can just drag it in from the world into our building we're going to need some materials for this positive and negative so go back to our assets folder and we can right click create make a folder material and in our material folder we'll create material we'll call this building positive and I'm just going to duplicate that rename new one to build buing negative we'll keep them simple I'm just going to make this uh debug mode first and I'm going to make the building positive we make this blue um surface type transparent and for the AL we'll just reduce that slightly and drag this on our Cube just to see it so see that there's a bit of a transparent outline there that's great so let's do that and again the negative one transparent make this red bring our Alpha down slightly there if you want to we can add maybe a bit of emion just to make it look a bit nicer we can drag in in our set a mission to True do that with this one as well pick our blue color up the intensity slightly now we've got our red material which is going to be our negative material and we've got our blue material which our positive material this could be green or any other color that you want I'm going to go for blue and red and again going to undo that so it goes back to is default material and then I'm going to come over to our build tool I'm going to drag in our negative material into the negative material slot and the positive to the positive and if we hit play you can see as we're placing this it's blue we look up in the sky we're not actually hitting something so the um position has gone red and it's blue when we are looking and if we left click to place have bit of an issue here so let's take a look at what's happening here that was on the place building call and it looks like we're not finding our default material I have a feeling um start isn't getting called before we're calling the place building I think what's Happening Here is we're calling Place Building directly when we instantiate it so start isn't actually getting called and in the final bit of this code we're actually going to be using the star um ality so I'm for now I am going to leave it there but I'm going to copy it into place building so we're going to get the renderer um when we actually place the building down and if we go back over to Unity and hit play should play that is working that was that first issue but now obviously it's spawning in blue at the time so it's thinking it the blue is its um default material uh that's fine that's a little bug that will get sorted when we actually implement the actual building system it's CU we're not spawning these in from prefabs what we're doing is spawning them in just based on the cube that's already in the world so here we've got this blue cube and when we left click we are instantiating this cube in its current state and then calling the place building function which is getting the default material of that quebe um hopefully that makes sense once we start using prefabs and spawnable scriptable objects to spawn these in they will have their default material set correctly um but for now just know that this is a little bug that will get fixed in future so now we're in delete mode but we can't tell if we're actually looking at something so uh let's just jump over to the code and we'll implement the uh Logic for deleting our item so over in our delete method build Tool uh in our delete mode logic um method we want to make a new variable do this above the delete mode logic uh method do private building and we're going to call this target building actually no I'm going to put it up here our spawn building and Target building so down in with this target building which I've just noticed has a capital I've been doing a lot of work in Unreal Engine recently and that's the kind of coding convention over there it's all capital letters there's none of this lowercase stuff really um so that's why I keep doing that but I've rename that toore lowercase T Target build and we're going to make sure that the thing we're hitting is a actually a building so we're going to make a variable called protected building and we can set this equal to our hit info do ligher game object dot get component in erent because it's the cube that has the slider on it top level object doesn't actually have it's just an empty it doesn't have anything of than the building script on it so we can say get component in parent component we want to get is a building comp and we're going to check to see whether we've found that so if protected building Equal to null and we can just turn because we haven't actually found building to look at um and then next we want to say if our Target building equals and we want to set Target building equal to the detected bu because we've not already targeted a building um and we've just found one so we can set that as our Target now next we want to check if the detected building not equal to the Target building this is essentially also kind of like saying if the target building was null we want to check whether that Target building is the same building that we're looking at and we also want to check if the target building is flagged for delete because if it is flagged for delete and this is the old building and we're looking at a new building we need to remove move that delete flag and swap its material back away from red to its oral so we can say Target building do remove delete flag and we can set the target building Equal to our protected building so again we're looking around in the world if we hit a building we're going to store it here we don't hit one this will be null so we can just return early we want to check if we've already targeted a building CU if we have we've probably already done something such as flagging it for deletion Etc and it's probably already changed it if we don't have a Target building then we've not actually looked at anything before so this detected building can be our our Target building however if the target building is is not null and the detected building isn't the same as the target building and the target building has been flagged for deletion and we're obviously we're looking at a different building so we need to remove the delete flag and then we can set our Target building to detected building saying the word building a lot I hope that makes sense if it doesn't let me know below and I can always try and clarify now say if the detected building equals the target building and the target building is not equal uh is not flagged for delete then we need to flag the target building for deletion and we need to pass in our negative material FL for so Target building flag for delete and we'll pass in our building material finally if get through all of this we can say if Mouse do current was pressed to this Frame then we are going to delete Target building Got Game object that destroy just the building script we to delete the game object that the building script is on and then we can just set Target building back to null just to just to make sure definitely null then we go back round we'll know that we've targeted a building so we detect a building and the target building is null which it will be we can now do the logic to set that building um flag it for deletion as well and over in our build mode logic we can also check here whether the target building is not n because if we're in our build mode we're no longer in delete mode need to remove the flag from that deleted object so here we'll just say if the target building is not equal to n and Target building got flagged for delete then we remove the target buildings delete flag so remove delete flag and set Target build back to because otherwise if we were targeting a building then we press Q to go back to build mode it would leave the target buildings material is red which obviously we don't want so with that done hopefully this should be fine let's go back over to Unity and this time get our building and just make a couple ofs for it so we can see this working hopefully hope work if not debug it so we'll hit play and you can see over here we are in place mode press Q to go to delete mode and you can see this is an bit of an issue here it's not returning it back to its blue material or its original material so why is that also I'm recording this on the hottest day of the year so far I am sweating just thought I would share that with you I'm also sorry if you can hear a fan in the background okay to solve that bug that was a bit of a stupid mistake on my part so we're going to return this so if detected bull if detected building is equal to null then we can return early what we need to do is here if our Mouse uh button was pressed originally this was destroying it then outside the if statement we would send it to null kind of at the end of each frame we would just setting Target building to null we only want to do that if we have destroyed the building so now we're saying if we are hitting something then do all this we're not hitting something and we have a targeted building which is flagged for delete we need to remove the delete flag and then set it to null so um now with those changes in place if back over to Unity and hit play and we go to delete mode and we can look here we've got look at the object and it red look away it goes back to material and we can walk in between these and set the objects to flaged for deltion then we can left click and um delete them from the world going to get rid these which I was using bugging purposes right so the last part of this video is getting the grid setting up so we snap the when we're positioning the uh building we are snapping it to a grid which we have a good amount of control over so do this we're going to go back over to Unity we going to go back to our build system scripts folder right click create C script and just call GD let's open up so here this isn't going to be a this is going to be a normal static class which we can get from anywhere as such we don't need void update start functions and here we are going to make a method going to call this public static and to return a vector three to say position from world three actually GD position 3D and we can open up some brackets so this is going to take in a world position so Vector three build we can also do a float this is going to be the scale brid scale sorry so grid scale so this is going to snap all of our Dimension to this grid that we are putting in so we just need to do a bit of mths here so we're going to say we're going to get an X variable we're going to set this equal to math f. round and we're going to round our world position do x uh divided by the grid scale dox times we're going to divide that by grid scale and then we're going to times it by scale to duplicate this times and we're going to do a y z and then we can return a new Vector 3 of x so what this is going to do so say if we have a world position and on the x axis we are 20 254 units away from the world center of 0 and then we've got a grid scale of three we can divide by three so that's going to be 84. 6666 to the nearest integer which is this case go up to5 so we do 85 do Times by three this will give our grid position on a world grid where the kind of grid snap points are on a scale of three this will give us an exp position of 255 so that's a nice round number that will conform to our grid scale of three no matter what uh we put into so so if I go back over so for example that was 254 we do 255 / 3 that is 85 which obviously if we Times by three that's 255 if we do 253 ided 3 is 84.3 if we run that up to 85 * 3 355 so it's going to snap to the grid when it's in these weird in between points and eventually we'll go down enough that when we times this up by three it' snap to the next kind of grid point along with that um class and need if we go back over to build tool and we go back over to our build tool script and then here where we're setting the position what we want to do is actually um we'll create a new um grid position variable and we'll set this equal to and we can go into to our world grid class do grid position Point pass in hit point then let's just pass in our grid scale of three um which what we wereing in Sample and we can set the transform. position over to grid position this is going to be our um position corrected to our world grid which scale uh as much want let's go over to see play you see as we're looking around this is now snapping it to a grid size of three place that down see that we've got our grid Point here there's a few visual bug so you can see that as we click our position it spawns in slightly behind ah okay that bug there is cuz when we instantiate it we're instantiating it at the uh actual hit info do Point that's not aligned to the grid object so let's copy this inside this else statement and we can use our grid position here instead of the HIIT info. Point drag go back over to our project and we can hit play and that should work now so we go over to our mode we can see here it's snapping as we'd expect and then we can click and it will put it exactly where we are clicking not where the actual Ray was hitting so that's snapping to a grid so you can see we are getting there we can now delete items from the world and place them into the world so again there's that visual bug where we leave the material blue when we place it down into the world uh that's going to be fixed in the next video um and we're going to work on actually implementing the building prefabs which look a lot more interesting than these cubes as we as well as implementing the ability to rotate them that's going to be in the next video which is already up and available over on patreon.com dmos if you want to head over there the link is in the description to get the full series and the project files um on the paid tier of the patreon and also for free you can get the models uh which we're going to be using in the next video um to follow along there so um y the link for that will be in the description thanks for watching and I'll catch you in the next video bye I'd just like to take a minute to thank my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP tier we have John SM and Trey Briggs and all of the wonderful 4,000 XP tier members are on screen now thanks again for your support hello and welcome back to the building tutorial Series in this part we're going to be working on implementing the building models so we've got something a bit more interesting to look at at than just this plain old Cube this we're going to be going to drive a lot of the data for the buildings by using scriptable objects which which I love I love scripts of objects they're very powerful they're really cool to use but before we do this I just want to quickly add the ability to rotate Parts um cuz we're going to use this uh later on and we're just going to listen out for the r key and if we detect it then we want to rotate the object by 90° um so to see this working we're going to have to to stretch out our cubes see give your rotate Cube it kind of look the same if you snap it by 90° so let's just um stretch them out a little bit so we've got our cubes here that nicely stretched out so yeah currently if we are um playing and we're moving this around and is snapping it'd be great if we could rotate it and you see a bit of an issue here because we've stretched them I think so because I stretched them they've shifted away from the game object Center so let's just uh zero those back out I thought that might happen but it looked visually hadn't and that have to uh move the top level building object along that one long this one's the one around the world so should be fine let's that so yeah there we go we're moving it around properly so let's implement this rotation logic and then we will get the uh building models imported them so back over in the build tool script like I playing last time I was in that but that's fine we're not currently playing right so we have our build tool script here let's um um at this point if spoed SP if spawned building equals null we're going to return anything past this point we know it's safe to do stuff to spawn building so we're going to say here if bo. current R key press this Frame all spawn building dot transform. rotate rotate it by 90° y AIS Z so 0 90 0 on rotate function then we want to store our last rotation in a global variable the reason for that is that when we choose another part from the list we want it to remember the rotation of the part before it otherwise if you're trying to build kind of a weird angle and then you keep you you know you want to swap between different parts they're going to forget their rotation it'll be really annoying you'll have to rotate each building piece back around to where it was so then you can place it down um yeah hopefully that uh so we're going to get a private querian I hate querian but we're going to get a private Quan let's call this last save our script go back down rotate logic here and we're just going to say last equal to spawn building transform. rotation and for now this instantiate we're not actually going to be instantiating the building uh when we click the left button been doing this as kind of t for now though we're going to keep it this way so we need to put in last rotation into function so if we now back over our play mode here and we can press R and we can rotate our part by around y AIS now obviously this could be a toggle you might want to allow players to snap between 90° but then they could have access to some sort of free rotation if you wanted um could have it you know as 45 uh in fact why don't we put this as a rotate snap angle float we can set this in the inpector then can't we so we do a serialized field private float rotate s angle set it as B to 90 and then back over project we can swap this to 5° press R and we could it by 45 kind of that direction do so so there's our rotate um soid a nice little quality of life feature but now let's jump over to the script of stuff um so let's right click create C script and I'm going to call this building data dot just building data so here in our building data script this is going to drive from object up here going to do a create asset menu menu name build building system slash build data data waying it um so we've got a public class building data this is going to have a few different things which will help feed the UI and the actual placement of the buildings we're going to have a public string and we call this display name have a public Sprite this icon have a public float grid snap size snap size public game object which is the refab the actual building model cck Vector three building size so this will be like the that building piece like how big it is the dimensions of it outside of this class I'm to make a public enum and this part and I'm going to have rooms corridors then we can make a public part type call this part type go and just as a little quality of life feature I'm going come down here going to wrap this next bit of code is if editor um processor directive I think it's called I always forget the name of that um and this is going to be a custom editor uses the unity editor namespace it's going to be custom editor type of building data so if we are looking at a piece of building data this custom editor will apply and we can make a public class called building data editor which drives from and we have a function that we can override called public um do override texture Tod render static this takes in a few different things um it takes in a string which is asset path uh an object array um you don't need to know all of this we won't use this um it takes in an object array called sub assets and int width int height and that is it so in here going to make a variable called our data this is going to be set Target which is going to be what we're looking at building data we just want to cast this to building data if you haven't done editor scripts before it's kind of beyond the scope of this video just follow along if you'd like to see some more um tutorials about making your own editor script let me know um I'll cover that in the future uh but just know we're making uh a bit of code which will run in the editor to just make our lives a little bit easier so check here if data equals again that's this building data if the data is null or the data icon so this uh variable here that's null then we will just return but if the icon to this Sprite icon is but if it gets past this we can make a new variable called texture set this equal to a new width and height pass in by default this method which we riding again we're not calling this anywhere the editor is calling this um so we're going to make a new texture with width and height editor utility dot copy serialized and the source is going to be the data icon. texture and the destination will be the texture that we have made then we're going to return that texture so that should hopefully work again don't don't worry too much about this bit of codee if you don't fully understand it um if you want to learn a bit more again let me know in the comments um now this is the main kind thing that we'll be using build system this is just quality of life feature I'll demonstrate in a second so we go over to our folder we go back over to our project and in our build system scripts folder I'm going to make a new folder called building data in here we can right click create and we've now got this building system build data this in and I'm just going to say test building for now you see nothing has kind of changed we just got the default scriptable object icon and but if we go over to the Sprite and choose a Sprite for now I'll just use UI Sprite see this now changes our scriptable objects icon to be that Sprite when we start to load in our data in a second you'll see that we put a little preview of the Sprite here and it will look like this so these are all of our scriptable objects Associated icon Sprites which we've set here so let's get started doing that so if you've head over to the link in the description and where to download this Unity p package file called building tutorial models and if you just drag this into your project see that it'll come in with the project uh icons materials and model folders we're going to use all of the going forward so just hit import and you can see that it's brought in this project folder with icons materials and models drag these in see them world floor sign Square building long building uh so they're all there for you to use so let's go back over to our building system script uh the data folder so our test building now plug in one of our y icons let's start with just this Square Room and going to rename this scriptable object call this Square R sometimes with that edit a script you'll get this error um it's fine you just clear it and go away it's like a bit of a editor error it's probably a bug I've probably not done the edit a script you know ful how it should be done but you know for now it works that error is fine you can just clear it um we've got a few different things here so we've got our display name so I'm just going to say Square Room with with our Square Room icon so for the grid snap size if we drag in The Square Room crosssection p l is just our normal Square we drag this put it at 0 going to make a copy so D remove this over three on I'm going to make move this over sorry six on the X you can see that these are done to kind of scale of six so for the grid snap size I I like keeping it at three because different parts can now be in multiples of three so I could have a three across Corridor for example or a you know something that fits within that modular snap setting um so if that was three that's overlapping so you won't be able to place that but if you go over another three fits perfectly so for all of these building data I'm going to put the grid snap size as three however if you're using your own modular assets you may want to set it to the actual size of the object so these are six um squ is 6x6 Unity units um I like to keep but the way I've done them is um three snaps quite nicely together so we'll fill in the building we'll fill in the prefab bit in a second but for building size as I said that with 6X 6 by six it's a square room um for reasons that will become apparent a little bit later uh what I do for building size is do the size of of it minus about 0.2 so instead of 666 we'll do 5.8 5.8 5. reason for that if I pull back in So this 6X 6X 6 is really up to the edge of this building if I duplicate it again and move it over six they're going to technically be overlapping they're touching especially on on the doorways um I didn't pick a great example but they are technically touching a little bit this building size that we put in on our scriptable object helps Drive the glider which we spawn to see whether the buildings are overlapped in so we want to make it just a little bit smaller than the actual itself so if you if you're using your own uh modular assets just take that into account so go a little bit under their actual size okay so as for this prefab what we need to do is to right click create an empty call this building undor Square Room zero this out now to this Square Room I'm going to get the model of The Square Room so this one just Square Room not l or t um that's to do with the amount of doors on them so Square Room what we'll do is drag that under our building Square Room prefab or empty which is about to become a prefab and then underneath this we need to right click create another empty call this gliders and make sure it's spelled correctly because we'll reference this by name in code a bit later on and make sure that's zeroed out and then then under the collider empty that we've just made create as many empties you need underneath that to them you add a box collider or any collider shape that you want and then this building currently has no Collision on so the player would be to just walk straight through it what we need to do is with these colliders position them kind of on the wall and this is because they're enterable building um if they weren't enterable Fable to just uh put a big box collider around the whole thing um to position that into place we we know our room is 6x6 put our collider on there position we'll do three and minus that should be on that wall perfectly kind of in the middle and the player won't be able to to walk through that wall you need to obviously cover the entire room so I'll duplicate this and I'll move positive three again now for the front obviously that's going to be a little bit different so we can make a new empty add a box this forward cross quite a tedious process I'm only going to do it the once camera in like real time jumping ahead um later on point you're watching me just do this it's the same sort of manual thing over again then we can move this up three on the Y 1.5 x so again just position this in a way that's not going to lock your doorway or anything lock the that over collisions are quite T there is ways to do in 3D program this uh intensive way what I'm doing here is I'm just duplicating some box colliders spin them around and above the doorer these three colliders four colliders three colliders here and take them and back then this side one okay rotate it move up to roof duplicate again move down I'm being very now that should be uh to position these you may want to go into 2D mode time to time and then you'll be get it like directly onto the floor like that um but if we hit play see the player can now walk on this and he can't walk through the wall out of it can't walk up we got to jump up step that's how you'd set up the collisions for these uh models again quite labor intensive but you know once you've got these um you could duplicate this um swap out Square Room leave the collider model in you can put The Square Room T in get rid of the other one and then just reposition gliders accordingly obviously now got one big square and it's covering that doorway so the player won't be able to get out of that um but again I'm not going to go through that whole process for every single video otherwise every single building piece otherwise that would go on for are too long um right so we've got this first one this Square Room going to come to our prefab folder which was already made for us um tutorial this first person sort of template it's good enough fors going to right click create folder building ref Fabs drag in square room into the tab folder and we can open up this and we can see it in the prefab window this may be a better place for you to then go manually put ciders back into bit of a better position if you want to tweak them okay so that was quite long-winded let's get back over into our scripts go to the buildings script that we've got I'm going to need to rework this a little bit to actually work with the building data that we've made so the way we're going to do this is we're going to the buildings directly through code the actual buildings won't be prefabs just the graphics and those colliders that we've just made and the rest of it is going to be driven by the scriptable objects that we're going to create in the vector so here in our building script let's um going to get rid of our start function fully do public void in it call it initialize if you want in it it's just nice and short and kind of we know what it means this is going to take in some building data data we would then want to store a reference to this so up the top here I'm going to do a private building data variable call this assigned data signed data equal to and we also want to store reference box collider and to make sure that it's got a box collider on it we can by component type of box glider oh glider that goes outside of the glass declaration y component type of box collider here now we know that if have a box collider we can private box cider box Collider in our initialized function say box collider is equal to get component box collider so we're going to set the Box collider size so box collider do size equal to the assigned uh yeah the assigned data do building size going to move this center of our box collider up to the center of our Graphics box collider do Center equal to a new Vector 3 we'll Z do some brackets here for the Y and we'll do zero Z then in y we'll do assigned data do building size doy plus 2f which is what we um took off remember when we uh put this building size in we minus 02 going to add the 02 back and then divide this uh sorry then times this by 0.5f so that's going to find as the exact uh horizontal center of our building we do time 0.5 instead of divide by two cuz it's slightly quicker doesn't really matter in this but um it's always better to multiply than is to divide then we want to set our box glider do is trigger then we need to add a rigid body to this building so we can detect collisions we do game object got add component add body make sure we set it to K don't physics will apply and you'll start getting weird things affected by gravity it'll fall down Etc we want it to be istic equal through now we also want a reference to a game object which private game object for this graphic to be the prefab that that we've just made so here we say graphic instantiate data. app and do that at the position of this script so our position set the graphic to be the parent of this um we'll set the building script to be the parent of the graphic as well by putting transform in there then finally we're going to get renderer and set this equal to um graphic. getet children getting the renderer component default material equal to renderer material so this is the stuff that we were doing then for that colliders um empty made so back over here we made a empty called colliders make sure you've spelled it like that or if you've called it anything else when I use the word colliders in a second Call It Whatever you put here and so I'm just going to copy title of this back over over to our script here what we can say is we can say sliders which is variable will make in a second this will be equal to graphic. transform. find and then we'll paste in whatever we named that empty and transform. find just looks down through all of the sort of children of that transform and looks to find a game object called iders looks to find a transform called make that so we do private transform and if we found any colliders we want to turn them off we actually place the building uh ifers not equal all then make do colliders do game object. set active while we're positioning the world around we don't want want it colliding with anything for example if You' got a multiplayer game you won't hit another player you want them to run through the kind of like hologram uh it's not physically there so we don't need ciders in there and even the Box collider we've set that trigger to true then when we place the building turn colliders back on move straight onto Bas build I'm going to move this of the update material function like that's place for it so in our PL building function we're going to turn the box collider uh we're going to disable it because place in the world now we don't want to block people getting into the building and we turn on um give sliders we can turn them back on do colliders game object. active through this time going to get the renderer which we've just got a reference to up here so we're going to say renderer do material then we're going to say update material and we back in default material which we got here when we spawned in the graphic I'm going to get our game object and we'll do dot layer equal to and we need to set this to our building layer we go back over to Unity go in our layers uh thing we can see here building got a 10 next to it it might be different for you we're going to set our building back to our um building layer cuz we're going to have a different layer for the building preview so uh whatever you've got as building uh the number next to it you want to put that number in here so for me it's 10 you it could be something different then I'm going to get the name I'm going to change the name of this uh building to be equal to the sign data. display name plus do an plus Dash plus transform then finally because we've got this trigger volume and we have a rigid body we can detect now uh when stuff is lapping s a reference to that so we can say private bull is overlapping and I'm going to make a public cap a getter for that private Ball come down here and we can say on trigger enter so private void on trigger enter say is overlapping actually this on trigger stay and we can say on trigger exit overing to false and I want to put underscore in my bo uh just to keep that to show that they're private variables that's our building script done for now so now we can go back over to our build tool script so here we're going to do a little bit well so so here I'm going to make a function choose part so private void choose part going to take in a piece of building and we're going to choose a AP from the UI eventually um when we click on the piece that we want to use this method and it pass in the data just selected so do choose part building data and we can open up set of curly braces and we want to do few different things in here so we want to check if delete mode is so if delete mode enable we need to check if we have a Target building because if we uh if we turn off delete mode we could have been looking at a building and we' leave its uh material as red and I want it so even if we're in build mode choose a new part it swaps back to build mode that makes sense so we say if the target building is equal to n and Target t for delete is true and we want to remove El flag set Target build turn off false let if we choose a part and we're in delete mode we just make sure that we sort out materials of anything that we were possibly looking at then we turn delete mode off now if we if we're choosing a new part and we've already got a part Chosen and we're in build mode and we're looking around and placing something we need to destroy that spawned building so we can bring in our next building so we say if if spawned building not equal to n then let's destroy building game object and set then we're going to make a new game object there for It Go game object set this equal to new game object instead of uh round braces I'm going to really braces here going to say layer equals and this is going to be our default layer in and name be equal to build semicolon so this default layer int this is going to be set in the inspector we could hardcode it like we did here doing the same thing need a new layer get the integer the kind of references that layer so if we go back over to our build to series and we add a layer I'll do layer 11 build user layer 11 out of that I just want to make sure that I've not that that so on our build tool change this to and then if you ever need to move layers around for whatever reason or you can do that with and you won't just come here and change that you won't have back into code where the build so to this new game object that we can now set our spawned building Equal this game object and we're going to add a component to it I'm going to add the script that we've just add it to it and store a reference to this new script that we' added call the initialized for passing in this data here then we can set spawned building do transform do rotation equal last ration so now in our build mode project down here this is getting quite big as well uh so we're going to spin out some of this method so here I'm going to get this put that I'm going to going to get this if keyboard current. R key was press this Frame down to this else here let's put that I'm going to make a method called position building let's make that method it can be a private void method paste in this here okay so what we want to do is this spawned building update material I'm just put this out of this if statement to place it at the top so so say form building. update material going update it based on whether it's overlapping say spawned building do ising question it is overlapping we're going to put our negative material in it's not we can pass in positive material and cut this get rid of this else statement and paste that into here and we'll get rid of not so we can say if the ray is hting something then let's place our building okay so let's just check this is so in our start method going to call chuse part method manually and we're going to um obviously again this will be driven through the U but for now let's just do it manually um going to make a temporary variable called public building data it data then we're going to choose part as in that data that we've just set we're going to set this in the inspector so that's going to choose the part and then we are going to hopefully spawn in our building and we should be able to place it down World ah so instead of now we don't need to instantiate the building when we C left Mouse button we just call uh fored building do place then we want to make a copy of our data so data copy is full to spawned building do assigned assigned data which we go over to our building script here we're going to make a public getter so public building data assed data which our private variable here go back to our build tools going to make a copy of the assigned data going to get our spawned building set it to null and then we can choose part and we'll choose our data copy placing the one that we've been moving around and then we'll spawning in a new one and starting the whole process go over to our project go to the build tool and we've got our data here we can select this drop down we've only got one it our Square Room delete The Square Room from the world and there's been an error oh that's because over in our Square Room building data I assume this is why we just lock that and then go to our prefab folder we can drag in this building that we made play okay so we can now place this part and you can see that we've got this kind of piece overlap anything we need to set um Vision kind of stuff up okay so the overlapping doesn't seem all figure that out in a second let's just poop out and have a look at this so we see our build preview here lock the inspector it's set to the build preview layer there's a box collider on it it's the right size it's going around and it's set to okay so you can see that working now uh there was a bit of an issue when with the kind of overlapping uh logic it was correctly detecting an overlap uh but left this line in so in the if is Ray hitting something um we just need to remove that line the mat what was happening was I was set the material and then I setting it back to positive if we so with that over to our play going around and if it overlap some um goes red in the minute we can still place it if it's overlapping just to fix quickly here we just want to say let's copy this if we press the left Mouse button and we are not overlapping something then we place the build so let's just check that that's worked so can't actually place a building while we're overlapping but we can go out here and place many building Parts asire long as they're not overlapping the AR key we canate so what you need to do now is a bit of homework for you between now and you go back to your building data script make a new one so create building system build data let's do where t the T Junction choose the room T right uh and all of these are kind of the same grid snap size of three building size 5.8 58 cu the square ones a square lay name now you need to sort out the prefabs so just like we've done here so what you could do is you could just duplicate it rename it build _ one t get rid of the we room drag in we room T you can see that this has got one door front and then of off to the left and right then you'll need to sort out all of Sliders back to the building data Square Room T this roof ABS folder this is the and then if we go back over to our build tool again we've got this hardcoded bit here we'll use D1 now with key Junction we can't get rid of that yet got our T here I can get in I don't think oh I can get out there I can't get out this side because I didn't sort the colliders out but there you have it so go through and do that with all of these models that we have here um with the long ones with Corridor straight long room and the observatory room I'll get these up on Scream now so you can see the building size here 8 by 8 8 by 8 11 by8 for the observatory long Grom which is 5 by8 5 by 8 and by8 and our Corridor is 5.8 2.5 and two so that those sizes are slightly different to the square rooms but it's the same process you just need to change the SI so that's your homework for now and next video um just to save obviously me doing it all in this video it'll take it is time con um so that was quite a lot to cover and it was quite a long video but hopefully but this has set us up nicely to create parts from walk around press tab we've got our different parts choose P so as always thanks for watching as mentioned previously the project files for this are available over on patreon as is the rest of the series as of now with the time of recording it's looking like there'll be six maybe seven videos but they're all up over on patreon which is patreon.com slos and in the meantime thanks for watching and I'll see you in the next one bye I'd just like to take a minute to thank my my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP tier we have John smart and Trey Briggs and all of the wonderful 4,000 XP tier members are on screen now thanks again for your support hello and welcome to episode four of our building tutorial Series going to jump straight in and so so far we've been hardcoding all of our building mechanics um you know we've been assigning it directly code or we've been you know in the inspector dragging bits of data in here then when we play it's spawning them in but we actually you know we need a bit of UI to help the player uh actually be able to interact system we are making so in this video we are going to be working on that working our UI this is looking like it'll be a two-parter we're going to set up and do quite bit of the coding of the UI system in this video and then in a follow-up video that one will hopefully be a little bit shorter but we kind of just finish it off before we head over to the save and load sort of part of the system so let's just get straight onto this uh I am going to come over here to our hierarchy and we want to get a rightclick UI and canvas now over on the canvas where it says UI scale mode we can say scale with screen size and I'm going to put in a reference so to our canvas I'm going to add a panel so right click your panel and we'll call this build panel to this we're going to add a build panel by script so we'll make that there we don't need to open that up just yet so underneath this one uh actually I'm going to make the color be kind of a dark gray dark black just get like that and then we can go over into 2D mode and then zoom out just make this a little bit more menu so we can see that dark and then I'm going to duplicate this and drag it as a child of our build panel and I'm going to rename this to panel and we'll drag this side like that and I'll actually call this panel top make it about there we might need to as we go and then to this we can add over in the inspector we can add a grid layout group and we're going to have a constraint we're going to have fixed column count and one column these are going to be out and to this I'm going to add three buttons I'm going to do UI button text mesh Pro which we'll have to import the EMP Essentials so on our button for the W transform I'm going to going to have it to size dynamically so we're going to have it um we say to stretch and fill the space and go over to our side panel here we can increase the X size of our button to fill our Zone like this uh side panel that we've made and our button text size minimum we'll put in Max will 50 minimum 16 and we're going to have uh three buttons one that says all part rename this to All Parts duplicate this see that the grid has dropped it beneath it so for this one set text to say rooms button again duplicate that this will be our Corridor but name this to now underneath this underne our build panel UI we're going to add another panel this time we'll call this the panel bottom and just size this to here that black bring up Alpha and to this uh bottom panel we're going to add a script this is going to be called build side UI building side UI sorry then we want to add a another panel be our item window that to fill this side again make black and this add a grid layout group as well now underneath this item window we're going to create an empty going to name it building and going to make another script called building part then to this we can add another button child on that so UI have it to we hold down alt and click this bottom right uh um stretch button it'll stretch it in all directions this is going to be the button that we use to click and actually select which um building piece we want to set the size of that by coming down to grid say8 by8 for example we can make that a bit bigger and we can change we're going to change what this looks like through code to show the um the Sprite of the build piece going to make and let's go back up to our canvas and this we can add one more script and call this the let's just go over to our build scripts folder and let's make a new folder in here called UI script get all of these scripts that we've just made and drag them over to our UI scripts folder then we're going to start off in our UI manager script that's going to be the script that we uh go to first so the first thing thing we want in here I'm just going to get rid of these left item back in OB but let's just start fresh so we're going to get a public build UI reference call this build okay so with that reference let's add back in our start method and we can say build panel. game object. set active to false so when we start the game we want the UI to closed then in our update function so here we can say if keyboard. current. Tab Key was press this time then what we're going to do is let's just toggle this panel on so build panel. game object. set active we're going to set it to the opposite of its current state so we say not build panel. game object active hierarchy so if it's open this will close it if it's closed open it let's go to check that's working so we've got our build panel script here and we just drag our in now when we hit play that should close do and if tab it opens tab it shuts we can still walk around and move with it open we'll change that um also have to show the mouse cursor well but that's that togg Ling on and off okay so let's just jump over to the building side panel I um we want to go to this panel here and we're going to add in my image I set that 256 but say by default go room just to see what it's going to look like and then underneath that we go UI text Pro text bre this down bre it out let's set this uh centered like that and let's just call default texted say Square Room looking at I think that's the T version so Square Room t on size a little bit um so now on the script this building side UI script going to get a reference to that image so Public Image unityengine.ui namespace say building image and then we can get a public TM eore text reference which is in the TM Pro name space and we can X then we can make a public void method so public void update side display which can take in data which will data that's just going to set our building image. Sprite equal to data. Icon and building text. text equal to data. display name so we'll use that and actually in a start function we can set building image. Sprite null building image. color color. clear and when we set our Sprite here we need to set the building image. color back to here we could do color. white and again just pop back into unity and assign those so image text actually in the start function of our building side I will set building text text that equal to an empty string so it looks like it back over to Unity hit play see that that's Now hidden let's get let's start stop this getting in the way uh for now just a little bit annoying uh we just go over to our build tool script start let's get rid of that choose part um section start method and we can now get rid of that building data now if we hit play we won't have a selected part at all yeah that's getting a null reference exception and we want to clear that reference build actually get rid of the serialized field from that we don't want to be that changed in Vector again let's hit play okay so there we go we're not getting any errors but we can't build anything now the idea is we're going to press Tab and then select on this UI thing to build get in there we get in there way there back out of this so now let's go to our building panel UI and what we want is a public building side UI we'll just call this side which when we choose a building part we can update that that image and text to the part that we've just chosen so public building side UI we also want a public static Unity action which is in the unity engine. events name space this is going to pass through some building data and we can call this on part chos then to this we want to add a public void on click will take in um building data call this chosen data and say one part chosen if there's anything subscribed to it let's uh invoke pass through the chosen data and then UI and update the side display pass through chosen data well so we're going to when we click on a button we're going to call this onclick event pass through that button's building data that it we're going to assign to it and then we are going tooke this event and then anything that's listening out for it we'll get access to this data so our build tool is going to be listening out for when this uh Unity action is called and it'll know which piece to spawn in for the player to place okay so now we need to go over to we're building part UI so here this is the button that's going to be over right hand side of the screen so what we need is a private button um reference called button and to use this we'll have to use the unityengine.ui namespace we want a private building data variable call this assigned data we also want a private build Peli method called erent display so in our awake function we going to say button equal to get component in and this be of type button and to that button we're going to listen for it to be clicked so we can say on click. ADD listener then we're going to add a on button click method which we make so private void on click when we click that button we're going to call this method this uh on button method on button click method that we've just made okay so now we also need a public void init function which is going to take in some building data call assigned data we can set assigned data so our Global variable we can set that equal to one that weing in then with our button we can get component going to look for for the image component of our button and set the Sprite equal to the assigned data dot this also wants to take in a um building panel UI reference for this parent display and we can set parent display equal like that so we're going to spawn these buttons in dynamically from um another script and then we're going to pass through the data that this uh building part UI button needs to know about and also the parents display so we can call a method on our building panel UI script and then in this on button click um method which we've created we're going to call up to our parent display going to access the onclick event there and we're going to through our data going to invoke this event going to update our side display so going to click on this button here um got a B build panel let's drag in our building side UI reference then we've got our building part here this button we got a building part UI what we want to do is drag this as a reference over into our UI scripts folder we can make a prefab of that and then we that from hierarchy okay so we'll leave that there otherwise this video will go on for a bit too long the next bit the next bit is quite a um evolved bit of coding but just so we know what's going to happen is that through code we're going to assign these um going to get these buttons and depending on which parts we have selected we're going to spawn in x amount of buttons we're going to be able to click on these buttons then choose the part that we're going to place world as I said that'll be covered in the next video this is a bit of a shorter one to make way for what we're going to cover in the next video that next video is available already now on patreon um along with all of the project files as well so feel free to head over to patreon.com dpos it's also linked in the description below as well in the meantime thanks for watching and I'll catch you in the next one bye I'd just like to take a minute to thank my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP tier we have John SM and Trey Briggs and all of the wonderful four ,000 XP tier members are on screen now thanks again for your support hello and welcome to part five of the building tutorial Series in this video we're going to be working on continuing with our UI so what we're going to do is we're going to have um our buttons spawning the different base Parts over here depending on which of these buttons that we click it'll be dynamic we'll spawn in the right amount of buttons for the right amount of parts that we know about and then this will allow us to click on a button button and choose that part then place down in the world so let's just head straight over to the code um I'm in building panel ui. Cs and there's a couple more variables we're going to need here so first off let's get a um public building data array this can be a known building parts we also want to get a public building part UI uh variable we can just call this the building um button prefab let's call it that and let's just jump back over to un so now on our build panel we've got our gnome building parts and our building button prefab which we created in the last part of this video series so we'll just drag that in here and for the known building parts we can lock this panel go over to the building data um folder that we have and I'm going to select all of these and then drag them over to known building parts so that that fills that array so now I'm going to make two um public functions I'm going to say public void and we can say populate um buttons and we'll say public void clear button then we need a couple more methods so we want public void um onclick all parts and do public void onclick room part and the final one public void onclick Corridor part and we're going to get our populate buttons here and what I'll do is I'm going to pass in a part type for this um chosen part type then from then from here I'm going to call our populate buttons function and for all parts um we'll come back to this in a second cuz obviously for all parts we're not choosing a part type we are um we want all of the parts so we're going to spin this we'll have two versions of this method um on click room parts we can say populate buttons we can pass in um part type room and place that for corridor parts to Corridor so let's just make another version of this function so public void populate buttons and this one won't take in um any arguments so in Click all parts we're going to call this version of our method and all the other ones we can call this version and pass in the chosen part type so let's now just jump back over into unity and on our build panel underneath side panel top we have these buttons so I'm going to come over here and we can get the onclick method me here and we can drag in the build panel script and we can choose um building panel UI and we can they onclick all parts for the rooms button drag in the build panel use room parts and on and on the corridor button drag in build panel building panel UI and Corridor parts now as we click these buttons we're going to do something over on this right hand side so we need to get a reference to this item window which has the grid layout group on it here and we can say public game object item window jump back over to Unity let's just make sure we assign that drag in our item window so we'll start with this uh method first The Chosen part type method so in here what we want to do is we want to we want to include uh using system. link and what we're going to do is we're going to make a new variable and we'll say we'll call this um room Parts I'm going to set this equal to our known building parts and then using link we can say where we open up some brackets and we can say P for part we say p which is our building data where P do uh part type equals our chosen part type then we can call two array like this so now we've got a building data array of everything that is a room if we're passing in room or um or Corridor if we're passing in Corridor and really we should call this um just like building now if we make another function called public void spawn buttons and this is just going to take in a building data array and we can say I'll just call this button data can call that from our populate button so we say spawn buttons and we'll pass in our building pieces and from this one which is all pieces we can say uh populate buttons and we can just pass in our known building Parts which is also an array of data so we'll do the actual um warning of the buttons here so we can say four each we believe this is uh VAR we can say for each um data in button data then we are going to instantiate our building part UI we're going to instantiate our building button prefab and for the transform we're going to say uh item window. transform and I'm going to store this button that we've instantiated in a new variable so we'll say v um Bond button is equal to this button that we are instantiating so now let's go over to the building part UI script which on our button so you can see that we've got this init function which takes in a piece of assigned data and a parent display panel so back on our building panel UI all we need to do here is say spawned button inane and then we can say spawned button. in it pass in the data that we're currently on in our Loop and then we can pass in this as the parent display and then but before we spawn in button we want to clear the buttons that were there previously so the way we're going to clear the buttons is we want to do a for each Loop and we're going to Loop through all of the children that are um attached to our item with so we're just going to say four each and we can say for each button in our um item window. transform cast to transform we're casting we're making sure that we're getting the transforms of all of our item Windows children and we're just going to call destroy item uh sorry button do game object but this should in theory be working so let's jump over to Unity and let's see what bugs are going to present themselves okay so every time we click back in our Mouse is getting captured so on our UI manager going to make a function do a private void um set Mouse C state which we'll take in a ball and we'll just call that new state and I'm going to call set mouse cursor State based on whether the build panel is open or not we'll pass in um so obviously we're setting the active in hierarchy variable here when we set it to active so that'll be its new state so we can pass that in um to our set mouse cursor state so here we can just call cursor dot visible is equal to the new state and let's call um set Mouse State here as well let's try that to see if that's fixed okay so that's showing the cursor we now need to unlock cursor so in New State we can say cursor we can say cursor lock mode do um then we want to say um cursor do lock mode uh lock State sorry is equal to cursor lock mode say cursor. loock state is equal to and then we're going to check this new State ball that we're passing in so if it's true and the cursor is visible we want to say uh cursor mode. confined which will just confine it to the game window and if it was false then we want to lock it which locks it to the center of the game window let's jump back to Unity try that so we'll press play and we can go over here and we can now click our buttons and you can see that these change depending on on which uh items got in place uh one thing you can see the word button is over our image uh we can just fix that so let's open up our building part UI and then um we can just delete the text from the button go back over to our scene and we click this open this up choose all parts and now all of our parts are there and if we click on a piece nothing happens but we can fix that so one thing we want to do is when we open up the window for the first time we want to make sure all parts is selected it looks a bit weird to have to click a button first so let's fix that issue first so what we can do is say uh we'll say if the build panel is now visible let's call build panel dot populate button and we won't pass in anything so that will will just populate it with the all parts but which will SP in um now let's go over to our building part UI and here in um our init function we can copy this out of the Awake And now when we initialize it it will get the button and it should add our on button click to our parent display uh and actually we need to put that down below cuz obviously we're setting the parent display here and then are adding The Listener to it let's try this out so we'll go back over to Unity and hit play compress Tab and now there is another issue let's see what that's going to okay so here we're trying to get the image component before we've got the button so let's get the button and then assign the on to that and let's press tab so we've got all of our building pieces we can select them some reason they aren spawning in the world for us to place and that would be because we're not actually listening out for that event so you can see here in that so in our build panel UI script we've got onclick we are calling onart chosen. invoke and passing through some chosen data but what we need to do now is on our build tool we need to listen out for this so we can say build tool and then in our um on enable function so we'll do on enable and we say building panel ui. onp part chosen which is that event that we've made then we can subscribe our choose part method here to that then if we just copy and paste this we'll change it to on disable and we can unsubscribe from that event we'll go back to Unity and let that recompile hit play so we're here we press tab to open up our menu you can see we're still moving around in the background that's fine uh we choose a building piece press tab to come out of our menu and we can now place that down in the world you can see that if we um rotate that to be at this like 45° angle Place one down let's go back into the menu and see if this works so we can press to get a square building and we've now got that in the world and you can see that it's remembered the last rotation so that's where that come to play and we can snap that down into the world uh one thing now is we don't have a way to clear um our selected object we'd want to be able to press say escape and clear the object which I will Implement in just a second but you can see we can go in here into our buildings we can now enter them uh so let's just do that little bit of clean up so on our build tool in update let's check for the Escape key so if we have a spawned building and um keyboard current. Escape key was pressed this Frame let's make a method called um delete object preview going to make this method it's going to be private void and we just want to we can copy and paste this bit of code here well actually we can cut and paste it from our choose part method we can cut that paste it down here in delete object preview and then let's call delete object preview here where we've just copied and pasted that code from and and now when we press the Escape key in our update function back here we are deleting our object preview so again hopefully for the last time let's jump back over to Unity and hit play so we can press tab we've got all of our parts here we can just go for our Corridor pieces and click for this Corridor piece we can place it down into the world and if we decide oh actually no we don't want to place that we want to do something else we can press Escape that gets deleted from the world we can Tab and we can actually put down this room that wanted to place that down in the world press escape and then we think oh wait no actually what we prefer is uh we want to delete that from the world we can press Q okay so been having I've been having a bit of a bug um there was two things so in our building uh do c s file in the update material function we can just put a renderer equals null check here and we can just return so if we haven't found the renderer let's just return it's better than filling up the log with errors and the other issue seems to come from you can see that if I choose to place down a part and place it out there get rid of it press Escape we can now see that if we click this the layer becomes upet and and for some reason a lot of these parts don't have their layer set and I think this has come from the fact that I copied and pasted these into my project you probably might not have this issue but if I select all of our uh assets and I'm just going to choose the building layer and we'll click yes change the children as well that should hopefully fix up the issue that I was having so if I press tab again go for this long building and place it down into the world drop over to delete mode and then you go you can see that that's working intended um so again you probably wouldn't have had that as long as all of your layers were set correctly um but again because I imported them from my other test project that was causing uh a bit of an issue so you can see that now we can delete objects from the world we can come back over here and we can Place some corridors down escape and then you know we can run over here and we can jump inside look out from our new base but sadly when we stop playing they disappear from the world and there's no way to bring them back so you lose kind of all of your hard work so that's why in the next um video we are going to work on saving and loading our created bases so we can bring them back into the world so that's going to be the next video video will probably be the last video in this series unless any other extra stuff comes up that people seem to want to see that video is already up now over on patreon.com dampas if you want to get it and you can also get all of the project files for this series so far over there as well but in the meantime thanks for watching and I will see you in the next one bye I'd just like to take a minute to thank my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP here we have John SM and Trey Briggs and all of the wonderful 4,000 XP tier members are on screen now thanks again for your support hello and welcome to the sixth and currently final part of the build system tutorial Series in this video we're going to be working on being able to save and load our beautiful bases that we're making as a prerequisite to this video I would highly recommend watching this video on screen now which I'll link in the description below and in a card up at the top I'm going to be retreading some of the stuff that I cover in that video so I don't want I'm not going to spend a huge amount of time on the kind of how to save data out of unity because I covered that in that video what I will be doing is using the stuff that we learned in that video to uh Custom Tailor it to our specific version of a save system that we need for our project so with that said let's just jump straight into doing this so I'm going to go over to our um test sort of scene here going collapse these down I'm going to right click create a new empty and I'm going to call this our uh base manager and drag this up to the top and our base manager up at the top and going to come out of debug mode normal mode and I'm just going to zero this out and then I'm going to come over to the script folder our build system scripts and I'm going to right click create um a new C script and call this our base manager drag this on to our empty we have to let that re reload pile and then we can drag this on over to our empty so we've got our base manager script here and let's open that up our so what we're going to do here is we want a um method called private void load base this is going to take in a class which we're going to make in a second called save data and then we are going to do some stuff with that class so let's go back to Unity and make the scripts that we need for our save load system and I'm going to put these in a new folder called save load we'll open this this up okay so the first thing I'm going to do is I'm going to right click create a new script we're going to call this just save load open this so again this is going to be um not a mono Behavior this is just going to be a public static class will save load and we don't need this stuff here so again this is what we've already created in that video which I mentioned at the start so I'm just going to type this up um as we go I'd highly recommend watching that video um but the first thing we need is a Unity public static Unity action called on save game and to use this Unity action we need to be using Unity engine doevents up here at the top we've got onsave game and then we are going to have another action called public static Unity action this is going to take in our save data class which we get to make again and we could do on load game let's just go back to our project and let's create that save data script we've now used in a couple places and that should solve those compilation issues we go back over to our script so we've got our save data class then I'm going to have a public static string called directory and I'm going to set this equal to a new folder called save data then we can have a public static string I'll call this file name and I'm going to set this equal to save game do sa for Save okay so first thing we want to do is to have a okay so next we need a meth method which we can call to actually save the game so let's make a public static save um function which is going to take in a piece of save data which we call data public static void and I'm just going to call that save not save data so we don't get confused as to what we talking about so in our save game function you can call our onsave game game event if anyone's listening just in case we want to do um anything with that we might want to pause the player while the game saves or show a screen or something like that um so we can just put that there uh we won't be using it for our purposes but that's there you do want to use it for your uh project and then we can make a string which going to call um directory which is equal to application. persistent data p plus our directory then we can check if the directory which is in system.io so you'll need to be using system.io we can check whether that directory exists and if it doesn't let's just make it so directory create directory and again in our directory so this is going to be our in our app data folder on windows and then it's going to add this directory onto it if it doesn't exist it'll create it and if it does exist then it's already there we don't need to do anything with that now we're going to make a new string uh which we could just call Json and this is going to use the Json utility and we can call the two Json function pass in our data which is our save data and we can pass in true for preprint which just organizes the Json file a bit nicer it formats it nicely so you can read it then we can call file. write all text pass in for the path our directory plus our file name and for the contents we can pass in on string and then I'm going to just debug.log just so we can see this saving game so let's now go over to this save data method let's go over now to this save data class here so this is just a data class it doesn't need to inherit from mono Behavior doesn't need start update and can mark this as system. serializable so this means that we can write this data out to a file we don't need these statements here so here we're just going to have a public list which actually we will need to reference system. collections. generic so we're going to have a public list of building save data which again is a class that we're going to make we're just going to call this our building save data and we want to make a Constructor for for this so public save data and we're going to set building save data equal to a new list of building data okay so now let's go over to our building script uh building. CS so in here outside of our class so below very last curly brace going to make a new class again is going to be system do serializable going be a public class for building save and in here we're going to have a string so public string for our building name a public building data our assigned data a public Vector 3 for our position and a public Quan for our rotation and we need to make a Constructor for this so public building save data string and this is going to take in a building name take in some building data which we call assigned data it'll take in Vector three position and a quan which we'll call rotation need to set building name equal to building name signed data equal data position equal to position ration equal to rotation so that's our building save data class made so now we need a place to actually store all of the save data from our base so we can go back over to our save load folder and we're going to make a new script called the save game manager which again let's open that up this is going to have a reference to some public static save data just going to call data in our wake function we're going to subscribe to the save load onload game um um function or event sorry going to make a method called data which will take in some save data then we're going to make a then because this doesn't have any data sort of assigned to it uh at the minute we can say data equal to new save data which again in our Constructor it's just going to make a new um list of building save data so when we load some data what we want to do is overwrite the data that we've made here with the save data that we've passed it just passed in so when we load up the data we're going to put it into our save game manager and then anything that needs to access the current save game or save file it can come to the save game manager to get the um reference to save data and we make this static so here we need um a method that our save and load button can call uh to do the kind of function it needs to do so I'm going to make a public static void and we can do try load data that's just going to call load from our save load script which we haven't actually implemented yet we've just done saving so let's just put that in so load is just going to be a public static load uh method public static void load and we need to get our full path so we can do string full path is equal to the application. persistent data path plus our directory plus our file name this is where our save file lives on our hard drive and we're going to make a variable called save data which we can set equal to a new piece of save data and then when we find if we find something at this path we can can set this variable to the save data that we found and if we haven't found anything we're just going to pass back an empty save file so here we say if file do exists at the full path so if we have a save file there we're going to do string Jon is equal to file. read all text at the full path so it's going to read our save file put it back into the Jon string then we're going to convert that back into some we're going to convert that back to our save data class so data equals Json utility do from Json reading that Json file back into the save data class so if we find a save file at our full path we're going to read that save file and then convert it back into a of save game file piece of save data and we can call on load game f and we can back in that data I'm just going to put an else and we can debug.log that the save file so back over to our save game manager we can now make a button that tries to load the data and all that does is call our load function over on Save load if that exists this onload game uh event will be called which we subscribe to here so load data will be called and then we copy our save data into this uh data variable we also want to call on Destroy and copy and paste this down here and then we can just do minus equals to unsubscribe and similarly we need a save data method need a method to be able to save our game private void private static with save data this is going to make a copy of our save data then we're going to call save load. save sync in our save data and we can debug.log that the so let's go back over to Unity and see where we are with this so let's go to our canvas and to the canvas I'm going to add our save game manager got that here save game manager underneath our canvas in side panel top I'm just going to copy these buttons here so Corridor button I'll just press contrl d contrl d and we'll duplicate them and this one let's say save base and this one we can do load base save button on our save button drag in our canvas go to the save game manager and call public static save data method and I had to put it as private this to be public so got our canvas dragged in there we can do save game manager save data and for the load button we drag in our canvas again this time we try load data through at the minute we aren't actually getting any data saving out because no none of our buildings are generating their own data but if we click play and we come up thing we can click save base we see um save key is being pressed and Save in game obviously that's called before uh the debug. log to save the save Keys press that's why that's first then we can also do load base um which doesn't currently work Sor right it does work it's just I was expecting a debug.log which we haven't actually implemented so we can put that there and we can say um loading save let's go back over to our project and just double check that's working so we press play and we can click load base and then we go loading save and that's because it's found our save file which if you're on Windows you can do um if you type in run and load up the run here we can do um app data in percentage signs that takes us to the app data roaming folder what we need to do is we can go back one and go to local low and here we've got default company and I've got building tutorial series and save data which is the folder and then we've got our save game here that default company comes from yeah where it says um company name and product name that's where default company build tutorial series came from here if you had you know your own games company uh name filled in then it' be local low your games company project name save data and we've got this save file which is just a text file we can open this with open it with notepad for example so here you can see our array which is currently empty um so that's what we're going to work on now so let's get that filled with some actual pieces of data so in our building. CS script when we place a building we want to generate a piece of data that says that that building is there that that's uh a building we want to generate a piece of data that lets our build our base manager know that there should be a building there to load uh when we call load base so let's go to building and at the bottom of Our Place Building function we can actually we need to just go up to the top and let's make a private building save data called save data just so we can store a reference to this and we just want to say here um underneath all of the code in our place building method we can do save data equals new building save data and we can pass in our game object. name which we've just set here we can pass in our uh assigned data we can pass in our transform position and our transform. ration and then we want to say if we want to check whether our save game manager doesn't already include uh a reference to this building because if it does we don't want to add it to the list otherwise we'll have overlapping conflicting data so what we're going to say here is if the save game manager doesn't in the building we're going to do is we're going to go to the save game manager to the save data and we're going to get this list of building save data and we're going to see whether it contains this piece of data that we've just made and if it doesn't which it shouldn't but this is just a good way of checking just in case anything's gone wrong we can do save game manager dot data dot building save data which is the list we can add our own save data to it so we're making here a new piece of data for this specific building so we we place down um a corridor this will be um Corridor plus and then it'll have its position that'll be the game object name the assigned data will be the corridor piece and we're storing a reference to its position transform. rotation we're going to check whether over on our save game manager we have our data which is our save data I'm going to check whether this list of building save data contains some data that we've just made which it shouldn't do because we've just created that class but this is just to be safe then we're going to access the save data and we're going to add a reference to ourselves to that so now if we go back to Unity and we hit play and we get some base parts and we place them down around and we press Escape let's go into our menu and we let's hit save base so saveing game save key has been pressed so now let's go back to that folder and if you're on Mac or Linux you'll have to look up uh Unity application. persistent data path and I'll point you in the right direction as where yours is but again on Windows it's in app data local low the name of your project company and project name build tutorial save data save game so now we can see that we've got our building Square 11 0 and - 8 8 0 - 17 - 2 0 23 so these are all of the buildings that we've put down uh just then that we've now saved out so now when we load the game our building manager or base manager sorry is going to know exactly which building should go where now just as a side note with our assigned data we're setting this through the inspector and it's coming up with this uh instance ID when you buil so these instance IDs are kind of assigned by unity against our building data so but these can vary in between the editor and uh scene changes and also the built version of the game just be aware of that if you save a game in the editor and then load it up in a built version of the game they may or may not load correctly you want them to load ideally what you'd need to do and it's beyond the scope of this kind of project is have a database which contains a reference to this assigned data which you can get by something that won't change so for example um in ID if that's not making any sense I'll have a link to this video um this is from the inventory tutorial series but it goes over how to create an item database to S of solve this issue um what I didn't want to do is kind of repeat information that's already out there um kind of extend this series uh longer than it needs to go this works but just make sure that um but just know that if you run into any issues with a save game in the built version of the game not loading in the project that's probably why so that's just a little bit of an aside as to what these instance IDs are doing but for our purposes it should work fine so if anyone does really struggle with that let me know and I can make it kind of I can do a follow-up video to explain specifically how we could do it for our project but uh watching the video that I've just shown on screen and that's in the description you should um be able to to figure it out uh you should be able to kind of work that out and do it yourself which is always a great feeling I think um but for now let's just jump back over into our base manager script so we are over here in base manager and we made this private void method called load base so what we want to do is in an on enable function when the save load system invokes the onload game event we want to subscribe uh load base to that event and on disable as usual we need to unsubscribe from that event so on Save load on load game minus equals load base so now we already know how to place buildings down new buildings and sort of Spawn them into the world we're doing it on our build tool CS script we're doing it here so we're making a new game object we're adding a building component we're initializing it um we're setting it rotation and then we call Place Building when we um click the left Mouse button so we need to do some of that again so let's just copy this over to our base manager and we can paste it in but we need to wrap this in um another for each Loop so we're going to say four each and we'll say for each building in our data. building save data which is that list of all of our buildings that we've saved out then we copy this in to here and for the name we can just set that to um building. name so the building name for the the layer we're setting that through code we're setting that in the inspector this default layer in and we could either hardcode it or on our base manager we could just make a public int called default layer int and then that solves that issue and now here in spawned building let's store that in a local variable over on the build tool that was a global variable so that's why that didn't work and what we want to do is we want to do all of this the same we're going to initialize the spawned building and we're going to pass in our data dot sorry we're going to pass in our building assigned data we're going to set the rotation to the building do rotation and we can set the position to building. position remember this building is our building save data so building name assigned data position rotation that's what we are doing here building is a piece of save data and we're accessing those um fields to initialize our building and then once we've spawned this game object into the world we can do build component we can say uh spawned building. Place building and we jump over to build to real series so we go back into our project now and unless I've missed something that should theoretically work so we're going to come over here and we've already got a bit of save data actually so we can press Escape uh tab sorry to get up our base and then we can click load base and you see that we've had a slight issue it spawned in one but then there was an error so let's just double check what this error was okay so I'm not sure why that wasn't working I haven't done anything apart from I restarted the project and now you can see that if we press Tab and load base it loads in properly and is even um storing our rotated buildings and we could go over here and let's spawn in this Corridor and spawn in another one and save our Base exit replay hit load and our base is loaded including the two new pieces that we put down there so I if you run into an error where you can't access your when you try and load you get an error um just restart your project hopefully that will solve it it works for me if it doesn't work for you let me know below and I can try and do a bit more investigation okay so with that working let's now make a on Destroy function and what we want to do is is similar to what we're doing in our place building we just going to copy this line and paste it down here so we're saying and get rid of the exclamation mark So if the save game manager does contain our save data then we need to uh remove it from our save data because obviously the game uh object is being destroyed so we let the save game file know that we're no longer there we can remove our save data from it and another thing we may want to do is here in our init function I'm just going to make a new parameter of build save data and I'm uh we'll call this save data and I'm going to set it equal to null just so we don't have to change any of our other methods we're just going to give it a default value of null and then down here we can say if save data is not equal to null then let's set our save data to this so if we pass it when we initialize it we can pass in a piece of save data and if we have we just set it to this private variable here so and again in place building we can just check to see if save data equals null then let's make a new new piece of save data and we're also going to check if it's contained here then we can um if it's not contained in our save game we can add it to our save game so again let's go back over to Unity and hit play and place a corridor down so we can now save our game so save base let's exit out the game go back into the game load our base so there is our base that we've just loaded we can delete some pieces from here we can save our Base exit the game hit play and we'll load our base back up okay so we had another little bug uh it's it's so hot today I think I'm just going a bit crazy speaking to myself alone in a very hot room in our base manager when we load our base I forgot that you know uh we are calling initialize here we added this building save data uh we just need to pass in the data back into that so uh we're calling initialize uh passing in our assigned script to block object data to say which building it is and then also we are passing in the save data associated with that so if we now go back over to the game we can see that we can get a long room for example let's rotate it and place it there we'll get a Square Room Place it down here maybe we'll do a bit of a corridor of rooms here like this and we'll hit save close the game load the game load base so we've got our buildings here that we've just spawned in now let's delete um those two and save our base out of play mode go back into play mode we can load our base and you see that the two that we've deleted have gone and we've still got our uh other one here and then we could uh add in the observatory building piece over here save quit go back in load our base and we've got the observatory piece and our square piece so that is everything that's all working now there was a few bugs towards the end that were driving me crazy but uh one was a restart and then we did a little bit more coding and then it seems to be working now if you do have any issues with that make sure to join the Discord server which is linked in the description below uh let me know there you can let me know in the comments here but it's easier to help you over on Discord as always the project files for this are available over on patreon.com pass if you do want to dig into the code and compare my code to your code thanks for coming along with me on this little Bill tutorial series uh I hope it was useful I hope you learn a lot let me know what you want to see next on this channel in terms of tutorials but for now thanks for watching and I'll catch you in the next one whatever that may be I just like to take a minute to thank my amazing patrons without whom I would not be able to do these kind of long form sort of Series in the 10,000 XP tier we have John SM and Trey Briggs and all of the wonderful 4,000 XP tier members are on screen now thanks again for your support
Info
Channel: Dan Pos
Views: 1,352
Rating: undefined out of 5
Keywords: unity tutorial, game dev, indie dev, game design, unity 3d, made with unity
Id: cf9tUWp1QyQ
Channel Id: undefined
Length: 163min 59sec (9839 seconds)
Published: Mon Oct 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.