🌐 Have you found the videos Helpful and Valuable? ❤️ Get my Courses unitycodemonkey.com/courses or my Steam Games 🎮 unitycodemonkey.com/gamebundle 💬 Here's a really awesome Building System that you can use to build anything, doesn't have to be actual Buildings. You can use it in a RTS, Factory game, Survival, etc. In fact I'm currently working on a Factory Automation mini-game where I'm using this system as a base for placing down all kinds of objects! It's super versatile so definitely look forward to many more videos using this system as a base! What do you imagine you can do with it?
Hi CodeMonkey! I'm trying to sign up on your website but when I click the validate email link it tells me 'Invalid validate link.'. Might want to check that out! Thanks for the awesome tutorials. You're the best!
I appreciate the videos, but they're extremely difficult to follow and implement due to: 1) Code structure changes between videos with no explanation 2) No explanation on how they're used in a particular scene (I realized that earlier videos depended on a 2D scene, later ones a 3D scene that's not compatible with earlier setups) 3) The source code links require registering for your website (annoying), and once downloaded the file is a unity bundle that then must be imported into unity to read, and also it's just one big cluster of random files and projects. The file I was looking for is a completely different name and structure as well from what's covered in the videos. Would be far better to just place source files in github and to not deviate from the format or naming at all.
I kinda agree with all of this. The grid things just kind-of grew over time, and later tutorials even just go about the "approach" rather than "1:1 follow the code" thing. Which I think is fine to a degree. But following along/checking out the source code is extremely annoying. I'd love to: 1) Redo the things aimed at more experienced users (like having the TGridObject fire an event when the value changes and have the grid be able to subscribe to it to loosen the coupling etc.) 2) Provide a GitHub with multiple branches being multiple-steps for people to check out themselves with clear-cut foldernames for ease of access I know making a lot of money is important to you and there's this whole youtube buzzwords and keeping videos short thingamajic going on. But if that is an issue, a multi-part series would be maybe cool too. Or just livestream it all and hire a dedicated editor for it? But bottom line is, I'd love for the codes and all to really just be on a public repo for people to check out with some clear-cut instructions. Said 'instructions' could be as simple as just making dedicated/'calculated' commits, each representing a new feature. That way one could compare files and what changed easily and also follow your new style of "tutorials" more easily. In fact I think I like that easy enough that I'll try commenting/suggesting it on a newer video for visibilities sake. As for 'converting' it from 2d to 3d, it's really just a change of the coordinates, or alternatively this video: ruclips.net/video/3zxTigjJr24/видео.html
Agreed. Really frustrated with how the format of the grid system tutorial series evolved. Impossible to follow along and the source files are just a big file dump. A compact github repository with only the absolutely necessary files with consistent naming would be huge and immensely helpful. Please fix this codemonkey. Thank you.
I know that the principle is probably the same no matter what, but whether it’s Unity, Unreal, Godot, etc, I am so amazed about all of the games ANYONE can make for free if you take the time to learn, iterate and understand. It feels so good what I thought was magic to learn exactly how it is, and it amazes me that many things in game design(well movies in general but I feel even more for games) are just a combination of illusions that come to make something great :) Thanks for all these videos!
Yup that is indeed an excellent thing. 10 years ago it was all magic and would take tons of knowledge to make a simple game but nowadays with all these engines anyone can make a game, it's awesome!
Wow, this is just amazing, looking forward to see the factorio style to finish up as I have a full game design that I want to make that needs this logic. Thank you !
Am really digging those helper functions that fixes the rotation and offsets based on predetermined values, before watching this video, i would have probably done it the hard way and tried to come up with "real time" solution that do some shenanigan calculations, when a simple enum and a couple of Switch-case could solve it, thanks man!
Game development has become so easy now. I started with unity and then got the curiosity to learn how to make games from scratch with c++ and it made me realize how easy it has become over the years. The code to render things in 2d takes a lot of code and time to write all those codes. But at the end when you run the program it brings tears of joy to eyes.
Yup the tools that exist nowadays make things so much easier, you need to be a genius to make your own engine, but anyone can open Unity create a simple script and hit play
Seriously , Tears are coming out of my Eyes ( I am Happy like Anything !!! ) i searched for a Video like this 2 months back but there were none ( Even Brackeys didnt teach this ) You now gave A Tutorial that is Interested by all Game Devs like me!! ( I can see that , just from the Comments ) I Dont know , who the Hell , Disliked this Video
I am a complete beginner when it comes to coding in C#. I am already familiar with some of the basics (ifs, fors, constructors and so on) however, it completely blew my mind how awesomly well this code is written, and how reuseable everything is really a great example of clean code. Thank you for the awesome tutorials mate. I have a lot to learn from you :)
Thanks! If you want to improve your programming skills I highly recommend the book Code Complete. If you read through the whole thing you will improve your skills 10x!
@@CodeMonkeyUnity thanks for the advice, definiatly gonna get that, however I am not a big bookworm. I tried to find online courses, coursera is what I am expriencing with. My only problem with online curses are either they are too advanced and I don’t understand a single world, or opposingly just the basics.
Great video, very clear and exciting. This system looks powerful indeed. I will also be interested in your implementation of a factory system. Thank you.
Instead of just storing a width and height for hte building you would need to store the shape, possibly with a bool array with true for occupied positions
This series of tutorial is really amazing, thank you so much for doing it. It is so good, I managed to reproduce everything in Godot and it works just like yours!
Hey Code Monkey, Great tutorial here! I really respect the stuff you do here on youtube, and even going and replying to comments on each of the videos, something I never see youtubers do. Keep up the great stuff! I was having some issues with making the visual ghost thing work in my 2d game, if you take video suggestions, I would love to see a video talking about how that all works for 2d and 3d games!
I made it offscreen but it's 99% the same as the regular Grid system that I made in previous videos on this playlist ruclips.net/p/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722 The difference is really just swapping the XY logic for XZ logic unitycodemonkey.com/video.php?v=3zxTigjJr24
How about adding something in ground of grid like (green for correct and red for not appropriate) making sure that the user can distinguish where to place like in other many games. Just my opinion 😅
Yup that's definitely an awesome addition, I've already made a Tilemap based on this Grid System so it would be super easy to add that on top of this ruclips.net/video/gD5EQyt7VPk/видео.html
C# dev here (build and maintain RESTful APIs for an insurance company) looking to try some game dev for the first time. Great video and love the emphasis on building tidy code / libs for re-use. Some random questions for you, how would you add a 3rd person controlled player to a tile system e.g. Factorio style player control? Does Unity have a Nuget style system? Also does Unity have enterprise options for collab for free e.g. TFS / Git style fork/branch/merge with auto-merge support i.e. flags code overlap with a Push / Pull, pipelines and unit test automation for CI/CD.
I created a system like this for my game except it doesn't use the grid system like that. It basically just rounds the vector coordinates from Camera.ScreenToWorldPoint to full values (1.0f, 2.0f etc) to "snap it" into a grid. I'm also using tilemap colliders to check the area beneath (some buildings can only be constructed on specific ground area and they can't be built on walls or other buildings. I'm also using raycasting to check if the area is a legal building space. I'm about to finish all my sprites for the buildings of my game. Just one more to go, but I had to check this video first to see how you are doing the building placement ':D
Yup that's pretty much the same method I used on the Freeform building system with some snapping on top ruclips.net/video/EpMFOeOMInM/видео.html It's a great simple system
Hello! Since I didn't see it in the playlist and was very confused about the newly-introduced GridXZ class, may I suggest you add the video about converting 2D systems to 3D into the playlist? ♥
Hey, ive been struggling with this as well. If you download the project files, you can actually find the entire GridXZ class code over there. I'm working on a 3D base building system, for my tutorial. So I came here to get inspiration.
The last part you completely missed to explain and show how you programmed. In the ghost script you suddenly have made the gridbuilding script to a singleton, without explaining that or how you make it a singleton for people who are new to that concept. The Onselectedchanged variable or whatever that is, came out of nowhere and finally the GetMouseWorldSnappedPosition function also out of nowhere. You should really explain these things or at least mention that you aren't gonna show this in the video cause this makes me feel like I've missed something but I've looked through the video several times and can't find that.
This could definitely be used as a level editor, combine it with a Save Load system ruclips.net/video/6uMFEM-napE/видео.html and you can even easily share levels.
Hello CodeMonkey, I followed your tutorial until you placed your first building at around 5:30. It did not work for me as expected, because the building was always placed in the first cell. After quick debugging I found out that the Raycast always returned a Vector3 zero, so that explains why the building was always placed in the first cell. I don't see you using any colliders on your cell, but as soon as i added colliders to my cells it started working. So I am wondering how did you make it work without using colliders on your cells? Could you please explain that? Thank you! :)
Really came in clutch for my RTS game! Only issue that i have, how to invalidate positions on the grid where the terrain is too steep bu build on. Gotta figure it out somehow. Thanks for the tutorial!
Hey CodeMonkey! Loving this video series so far. I think I'm missing something, but how are you able to "spawn/instantiate" what looks like building prefabs using "Transform"- more specifically, at 4:04. Thanks!
Transform and GameObject are pretty interchangeable, you can spawn the entire prefab with either reference. Every Transform is always attached to a Game Object, and every Game Object always has a Transform component.
Hi, thanks for all your content! It helps me a lot - not only with Unity, but also with the "game dev thinking"! :) I have a question related to this. What will be the approach, when the terrain will be not flat? It will be easy to implement the different terrain heights? Thanks for hint :)
The simplest approach would be to keep the underlying Grid flat and only snap the placed objects to the terrain. But if you need the Grid to match with the terrain perfectly by area then that's much more complicated, not exactly sure how you could do that, probably need to take the Terrain mesh and make a simplified Grid mesh while keeping the rough terrain shape.
Fix for those who are getting null references for the CanBuild() check for multi-grid buildings along the edges of the grid and couldn't fix it themselves: bool canBuild = true; foreach (Vector2Int gridPosition in gridPositionList) { //this is the fix if (grid.GetGridObject(gridPosition.x, gridPosition.y) != null) { if (!grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild()) { canBuild = false; break; } } else { canBuild = false; break; } } all you have to do is to check if grid tile returns GirdObject, and if it doesn't then you can't build there
Amazingly good tutorial. Just a question. When you implement the destruction why not just store the vector2 list used when instantiating. On destruction you just access the list from the transform you allready have and delet the object and then clear the transoform. I find the solution you provide much more complicated. So essentially instead of reverse enginering the Vector2 List just Store it.
I know you get some flak for the way these tutorials are structured but I love them, filling in the gaps and creating my own solutions is so much better than just mindlessly copy pasting the whole thing
Thanks! It's hard to make everyone happy while also making free videos and satisfying the RUclips algorithm. I'd love to one day take everything I made in this Grid System and make a nice easy to follow step by step course
Question: Are you using raycast to detect mouse position ? cause i remember in the original Grid system video you converted the mouse Screen Position but i dont think that would work for the z-plane isn't ? Edit: Nevermind you answered this question @5:16 , no idea how i missed it the first time i watched this lol
I have multiple questions: Is the "Heat Map" scripts required to make this work The Generics from "Powerful Generics" required/helpful to use If i wanted to put this into a 2D game, is all i have to do is put 2D instead of 3D and Y instead of Z
Great video/series. Really helpful! Having some trouble with grid out-of-bounds cases, both in object placement and for the ghost visual. Trying some things without success. Hopefully I'll get it working correctly eventually. In the first, I get a null reference error for object reference not being set on an instance of the object. I've seen some comments about it but can't get it working right. In the second, the ghost visual is visible and its transform follows the mouse outside the grid. I need to disable it when outside, and re-enable it when inside the grid. Not sure if the same happens in the video's implementation since the topic isn't covered a lot in it.
To avoid null refs the simple solution is to always validate the position, just a simple check if x,y is > 0,0 and < width,height I don't remember how I made it in this demo but yup that's one option, let it follow hte mouse exactly if there's no grid position underneath or leave the ghost on the last valid grid position. Although if you were to use this in a complete game then chances are the play area is much bigger than what I used in the demo so going out of bounds is less of an issue.
Hey, I love this tutorial and definitely could use it in a project in the future. But, I have a suggestion for a future video that could expand upon the grid system. I wonder if there is a way to take the grid and use it to generate terrain and buildings on a map. I’m thinking of a system like ACNH, where an island is a general shape but that the game would randomly generate all the terrain features on a grid inside the blinds if the island so each time you played you got a new island layout (which can be customized if desired later in the game). I’m sure it’s probably a huge ask, but I think it would be a great addition onto the series of grid related tutorials you have.
Using this for a terrain system would definitely be interesting. Usually random generation is made more with Perlin noise but you could apply this system in the end and do something interesting with it. I'll look into it, thanks!
Mainly personal preference. If you call Instantiate(); on a Transform you get a Transform and if you call it on a Game Object you get a Game Object All Game Objects have Transforms and all Transforms are attached to Game Object so both those types are pretty interchangeable.
Hello, so I have some advice for those using unity version 2022+ just incase you having some issues, 1 -- when downloading CM's assets for any of his videos if you already have script's with the same naming structures both Unity and Visual studio are going to throw a fit, simple fix is to use /* above the using statement's and */ at the very last line of the CM script's, this clear's most of the issues in the project for the script's and still allows you to use them as reference when solving issues, 2 - if you import the scene it can some times have issues that I haven't found a fix for, best to not import that and simply rebuild the scene normally doesn't take very long, also don't import anything that say's URP or Setting's for some reason this causes issue's I'm not sure why Better to just import URP into your project or, start a project already setup for URP, 3- best way to add your own prefab's to replace pink/purple issue with visual's is to use the same structure as CM, by adding a prefab with the logic, then having the script logic instantiate the visual of your choice as a child of the parent(what the logic script is attached too), then changing what's needed in your script's to fix any other issues that are still persistent, as for an easy ghost prefab can just have the material set to 50% or so transparency and then have it set back with code after the prefab as been placed/Instantiated(this worked for me, might try it urself), 4 don't forget to also download and import CM's util's, or build some of your own with the same naming structure to prevent having to change a ton of code.. if u have other issues after doing this I apologize as I'm still new to a lot of this as well and not sure how to help, Sorry this was a mouth full! Ps. CM in the part of this video where you check to see if a building is occupying multiple point's on the grid, is there any advice you can give if I wanted to check if a unique oddly shaped object where to be rotated and which part's of the grid where at the closes co-ordinance and then make the grid with a value of Range(x etc.) or a bool of T/F change the underlying grid values, I've been trying some ideas on my own to get this to work with no success so far, any advice would be helpful. With that said, Thank you for your video's as they have been a great source of learning both programing and game development as well as clean coding technics. I look forward to continuing to watch and learn, Keep it up your doing Great! (I'm using unity 2022 3d URP project setup and have had no issues after fixing the above Hope this helps!)
Thanks again for a great video. One thing I would like to understand is how you size your tiles to match with the grid? For example, if I have a path that I am trying to lay out, how are they sized properly for a grid that is larger than the unity unit?
@@CodeMonkeyUnity thanks for the quick reply! Scaling the visuals up led to blurry images but I may just need better images. Also when creating the backgrounds for paths and such it was hard to place them properly without the help of the grid in the scene
@@CodeMonkeyUnity Ah that completely makes sense now that I've had a chance to check it out. Once I added the 2D Tilemap I simply scaled it to match the grid size (10 in my case), and the tiles from the palette naturally lined up without any fuss. Thanks so much! And I purchased your Builder course today too given how helpful you've been! Thanks!
I am having trouble getting started with this. I went back and watched the first video, and now this one doesn't make sense really. I downloaded the files and looked in there and can't find a GridXZ script. Was that in a different video? I am also getting some errors.
This playlist isn't designed as a step-by-step course, I've just been building systems and expanding upon it over time, so there are changes between the videos. Watch the whole playlist to learn how the system works and then look in the code yourself to fill in the gaps. What errors do you see?
@@CodeMonkeyUnity The errors I think I saw were things about the generics and how GridXZ wasn't a thing. There might have been two more but I can't remember.
for some reason when i place a building it only places on the x part of the grid and doesn't go on the z part. this occurred after around 6:30 when implementing the instantiation on the grid and not just anywhere you click
nevermind i found the issue. it was with the gridxz script as i was working from the first video one the playlist making the grid system and when altering the class to the gridz i missed one single ".y" when changing them to lol
You should update your grid video to include 3d (x , z) alignment . i see you do it here but even though i spend over 2 hours after watching the grid video searching your other videos about where you did that i didn't find it
It's really just swapping XY for XZ, all the logic is exactly the same ruclips.net/video/3zxTigjJr24/видео.html Both Grids are included in the project files for this video, you can download and compare them
Hello Sr, I wanted your opinion on this: Say that you had this Grid class, but adapted to work with 3 dimensions "int[ , , ]", to make minecraft let's say. I was thinking that you would need a class to store all the chunks in the scene, but since minecraft it's practically infinite, you probably don't want to do that. How do you save each chunk? I know that you would have to save them separetly, like, the easiest solution that I can think of it's make a json out of each chunk and when writing this to a file, name the file with the coordinates of the chunk so you can get it back easily. The think with this, is that I know that minecraft saves all of the stuff in one single file, my question is how? How do you make each chunk a string and the put them all togheter? string.joint does this, but then how do you get the ecxact chunk that you want back? string.split get's you a list of arrays, and you could place it all in a order where you could track your chunks back, but still you have to get all your chunks at once from file to string, and Idk, I was wondering if there's a solution that I'm not thinking of...
Turning this into a Voxel System is definitely something I'd like to explore but haven't done any research yet. The idea would indeed be pretty much like that, split the world into chunks and make a save system to save each chunk. JSON would indeed work since it's just a string, I would make a main save file and in that main save file I would store a string[] to store all the JSON strings for all the chunks. Then each chunk save JSON knows where it's placed and what buildings/blocks are on it. I made a save file a long time ago for a Highscore table, it's pretty much exactly the same thing except saving world chunks instead of highscore entries unitycodemonkey.com/video.php?v=iAbaqGYdnyI
This is Really Awesome :D Next how to save every thing and also Load? This gives me idea of Track Bulder inside my racing game, sort of like parkEditor in Thps 2-4, or TrackMania :D if only i had money to hire you :D
Yup you could combine this with the Save system I made previously ruclips.net/video/6uMFEM-napE/видео.html and you'd be able to save the grid with all the buildings and even share the save file with friends.
Hi CodeMonkey, very good video by the way but even having understood the subject as a whole, I can't figure out how to make sure that I already have a structure placed on the grid and make it possible to move the grid during that the game is running and not just create it at startup? Your content is always so refreshing and a source of motivation, good luck for the next :)
Quite late answer but... His grid system have a Vector for the origin position, if i remember well (there is couple years i don't use unity anymore) i used to change the grid origin to move it if needed.
hello code monkey, I have a bug, every time I click out side the grid the scene stop. and I have a question, how to check continuously if the player can build or not, cuz right now it just check every time I click.
I Have to slow the video down to try to keep up with you but my efforts are use less..lol I’m. Not able to understand what’s happening and how it’s happening... but I’m learning and this is by far one of the best videos I have found to try go threw the code on... thanks..
Very nice video! Could you make a follow up and explain how you could make a more-dimensional grid, for example for multi story houses? That would be very nice and awesome.
By any chance, do you have a starting point tip on how to move the grid while playing the game? Like in the Update() method? If not, I'm gonna try to figure it out myself somehow. Thanks anyway for the great grid system, you're such a help.
Hi, thanks for the video. where can I find only the utils and the scripts that you dont show on the video? I dont want the entire project but on most of the script i cant use because I miss parts like the scriptble object
You can download the project, import it to a separate project and then take only the parts you want onto your own project Or just the utilities are here unitycodemonkey.com/utils.php
You just have to swap the XY logic for XZ. It's a very simple process so I didn't cover it in a dedicated video, you can look at both scripts side by side ruclips.net/video/3zxTigjJr24/видео.html
@@CodeMonkeyUnity wow thank you. I didn’t expect a response from anyone let alone you! I got confused as I saw things like TGridObject which I do not recognise. I will try to figure it out now! Thank you!
Also. With downloading project files. Do you need to pay. Or are they just not working. As if I try to download them to compare code or something like that it fails to download
@@CodingWithBen Maybe the server went down for a bit, try downloading again, there's no need to pay TGridObject is a Generic ruclips.net/video/8jrAWtI8RXg/видео.html
🌐 Have you found the videos Helpful and Valuable?
❤️ Get my Courses unitycodemonkey.com/courses or my Steam Games 🎮 unitycodemonkey.com/gamebundle
💬 Here's a really awesome Building System that you can use to build anything, doesn't have to be actual Buildings. You can use it in a RTS, Factory game, Survival, etc.
In fact I'm currently working on a Factory Automation mini-game where I'm using this system as a base for placing down all kinds of objects!
It's super versatile so definitely look forward to many more videos using this system as a base!
What do you imagine you can do with it?
Hi CodeMonkey! I'm trying to sign up on your website but when I click the validate email link it tells me 'Invalid validate link.'. Might want to check that out! Thanks for the awesome tutorials. You're the best!
I dont find the building sound in the Unity package?
My unity protect says that it cant find the GridBuildingSystem3D file
(Using Unity 2020.3.12f1).....Started clean, new project, tried to import the unitypackage, and there are 57 errors.
Am I missing some dependencies?
@@peterbelanger4094 What errors? Make sure you're using URP and Cinemachine
I appreciate the videos, but they're extremely difficult to follow and implement due to:
1) Code structure changes between videos with no explanation
2) No explanation on how they're used in a particular scene (I realized that earlier videos depended on a 2D scene, later ones a 3D scene that's not compatible with earlier setups)
3) The source code links require registering for your website (annoying), and once downloaded the file is a unity bundle that then must be imported into unity to read, and also it's just one big cluster of random files and projects. The file I was looking for is a completely different name and structure as well from what's covered in the videos.
Would be far better to just place source files in github and to not deviate from the format or naming at all.
I kinda agree with all of this. The grid things just kind-of grew over time, and later tutorials even just go about the "approach" rather than "1:1 follow the code" thing. Which I think is fine to a degree. But following along/checking out the source code is extremely annoying.
I'd love to:
1) Redo the things aimed at more experienced users (like having the TGridObject fire an event when the value changes and have the grid be able to subscribe to it to loosen the coupling etc.)
2) Provide a GitHub with multiple branches being multiple-steps for people to check out themselves with clear-cut foldernames for ease of access
I know making a lot of money is important to you and there's this whole youtube buzzwords and keeping videos short thingamajic going on. But if that is an issue, a multi-part series would be maybe cool too. Or just livestream it all and hire a dedicated editor for it?
But bottom line is, I'd love for the codes and all to really just be on a public repo for people to check out with some clear-cut instructions. Said 'instructions' could be as simple as just making dedicated/'calculated' commits, each representing a new feature. That way one could compare files and what changed easily and also follow your new style of "tutorials" more easily. In fact I think I like that easy enough that I'll try commenting/suggesting it on a newer video for visibilities sake.
As for 'converting' it from 2d to 3d, it's really just a change of the coordinates, or alternatively this video: ruclips.net/video/3zxTigjJr24/видео.html
Agreed. Really frustrated with how the format of the grid system tutorial series evolved. Impossible to follow along and the source files are just a big file dump. A compact github repository with only the absolutely necessary files with consistent naming would be huge and immensely helpful. Please fix this codemonkey. Thank you.
to go from 2D to 3D just go to the grid script and on getvalue(for the world pos)
change from vector3 (x,y) to vector 3 (x,0,y)
but you are right for example the Mouse3D he dont have it in the utils so i have to do it myself
but still now i know exatly how to do it
me too, it's hard to follow. Goes so fast.
I know that the principle is probably the same no matter what, but whether it’s Unity, Unreal, Godot, etc, I am so amazed about all of the games ANYONE can make for free if you take the time to learn, iterate and understand.
It feels so good what I thought was magic to learn exactly how it is, and it amazes me that many things in game design(well movies in general but I feel even more for games) are just a combination of illusions that come to make something great :)
Thanks for all these videos!
Yup that is indeed an excellent thing. 10 years ago it was all magic and would take tons of knowledge to make a simple game but nowadays with all these engines anyone can make a game, it's awesome!
OMG SERIOUSLY, THIS WAS EXACTLY WHAT I NEEDED AND IT JUST CAME OUT. sorry for yelling xD
I'M GLAD YOU'RE EXCITED! Thanks!
@@CodeMonkeyUnity is there a basic tutorial of making a game?
cause I started learning a week or two ago
@@GhostSlayerYT I covered Unity Basics here ruclips.net/video/E6A4WvsDeLE/видео.html
And C# Basics here ruclips.net/video/IFayQioG71A/видео.html
@@CodeMonkeyUnity oh thanks
And c# means the scripting part right?
@@GhostSlayerYT Yes
Wow, this is just amazing, looking forward to see the factorio style to finish up as I have a full game design that I want to make that needs this logic. Thank you !
It's fantastic... that's what I was searching so long. Thank you, Code Monkey. You deserve millions subscribers as Brackeys
NIce finally i can build my own city 👍👍 I might upload the city that I built with this tut
Am really digging those helper functions that fixes the rotation and offsets based on predetermined values, before watching this video, i would have probably done it the hard way and tried to come up with "real time" solution that do some shenanigan calculations, when a simple enum and a couple of Switch-case could solve it, thanks man!
Glad to see that many of your new videos are getting better views!😜
Thanks! Yeah it seems people have enjoyed the last few videos!
Code Monkey coming in clutch with the tutorials everyone wants.
Thanks! I try to give the people what they want!
@@CodeMonkeyUnity yea u r awesome tnks a lot
3 years later...thank you Code monkey... you don't know the length of good you have done 👍
heh I'm glad the video helped you! I also love how some tutorials are somewhat timeless
Game development has become so easy now. I started with unity and then got the curiosity to learn how to make games from scratch with c++ and it made me realize how easy it has become over the years. The code to render things in 2d takes a lot of code and time to write all those codes. But at the end when you run the program it brings tears of joy to eyes.
Yup the tools that exist nowadays make things so much easier, you need to be a genius to make your own engine, but anyone can open Unity create a simple script and hit play
Oh thank you so much!!!! I was struggling to find something similar to this for weeks. Cheers!!
Seriously , Tears are coming out of my Eyes ( I am Happy like Anything !!! )
i searched for a Video like this 2 months back but there were none ( Even Brackeys didnt teach this )
You now gave A Tutorial that is Interested by all Game Devs like me!! ( I can see that , just from the Comments )
I Dont know , who the Hell , Disliked this Video
I'm glad you found the video helpful!
I have a question. Has anyone ever told you that you are a FUCKING BOSS? :D
This is probably one of the most useful tutorials for starting a cool game system ever! THANK YOU! :)
I'm glad you liked it! Thanks!
you don't know how long i've been looking for this
I am a complete beginner when it comes to coding in C#. I am already familiar with some of the basics (ifs, fors, constructors and so on) however, it completely blew my mind how awesomly well this code is written, and how reuseable everything is really a great example of clean code. Thank you for the awesome tutorials mate. I have a lot to learn from you :)
Thanks! If you want to improve your programming skills I highly recommend the book Code Complete. If you read through the whole thing you will improve your skills 10x!
@@CodeMonkeyUnity thanks for the advice, definiatly gonna get that, however I am not a big bookworm. I tried to find online courses, coursera is what I am expriencing with. My only problem with online curses are either they are too advanced and I don’t understand a single world, or opposingly just the basics.
when I create everything up to minute 5:28 it works, but: the object I have as prefab is always created at coordinates 0,0,0 any way to fix it?
Sounds like you have an issue with getting the mouse position. Either no collider or you're in 2D unitycodemonkey.com/video.php?v=0jTPKz3ga4w
Great Tutorial. Thanks for putting this together..
Dude, this is exactly what I was looking for for my Homepage system. Thanks a lot. This pretty much refines what I was trying to make.
Great video, very clear and exciting. This system looks powerful indeed.
I will also be interested in your implementation of a factory system.
Thank you.
Looking forward to your next game, I've 100%-ed almost every game you've released!
That's awesome to hear, I'm glad you liked them! Thanks!
Sweet and quick tutorial, perfect to acquire experience in coding. Thanks for the knowledge!
Great video! It really helped me with the implementation of my game! Nice work 👏
Awesome tutorials!!! Keep up the good work!
Thanks!
Amazing video 😁
Good stuff, thanks for the tutorial! 😆
omg ive been building my grid system these days. perfect!
Timing for the win
is there any chance that we get a conveyor tutorial that goes along with this?
I'm waiting too !
I am working on that Factory game and, while not a full tutorial, I will definitely mention how the conveyor belts work
@@CodeMonkeyUnity I hope that's a type of project that you could share it's source code
Awesome Sir 🔥🔥
Wahhhhhh awesome, this is what i need. Thanks 🔥❤️
Hey, great video as always!
But I do have a question.. how should I go about implementing non-rectangular buildings? Think of sort of tetris-shapes.
Instead of just storing a width and height for hte building you would need to store the shape, possibly with a bool array with true for occupied positions
Love this video so much 👍👍
Yoy're the best! Thank you so much for sharing your knowledge with us!
Hi! Really great video! How would you handle L shaped buildings? Maybe an idea for the next video :)
Awesome!
hello dude :3
@@age9502 hi :v
I literally needed it like right now thanks code monkey
Holy chicken wings this tutorial was uploaded at the perfect time!
This series of tutorial is really amazing, thank you so much for doing it.
It is so good, I managed to reproduce everything in Godot and it works just like yours!
Nice! Best of luck with your game!
I love your tutorials .
Any chance of a grid fog of war tutorial? (Like the aoe2 where you can see building you discover but not units ) Thanks for all your tutorials
That would be interesting, I'd definitely love to do some more RTS tutorials
why not just use 2 layers for that, one that render things you want to see and other one to exclude units unless in sight
Hey Code Monkey, Great tutorial here! I really respect the stuff you do here on youtube, and even going and replying to comments on each of the videos, something I never see youtubers do. Keep up the great stuff! I was having some issues with making the visual ghost thing work in my 2d game, if you take video suggestions, I would love to see a video talking about how that all works for 2d and 3d games!
Perfect! Thank you very much!
You quickly showed that you make a game, with conveyor belts.
Will there be a tutorial with them?
I am working on a more showcase video rather than a step-by-step tutorial but yes I will mention how the belts work
Helps a lot thanks
Where does the GridXZ come from? I watched the tutorials but I didn't see it anywhere.
I made it offscreen but it's 99% the same as the regular Grid system that I made in previous videos on this playlist ruclips.net/p/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722
The difference is really just swapping the XY logic for XZ logic unitycodemonkey.com/video.php?v=3zxTigjJr24
How about adding something in ground of grid like (green for correct and red for not appropriate) making sure that the user can distinguish where to place like in other many games. Just my opinion 😅
Yup that's definitely an awesome addition, I've already made a Tilemap based on this Grid System so it would be super easy to add that on top of this ruclips.net/video/gD5EQyt7VPk/видео.html
C# dev here (build and maintain RESTful APIs for an insurance company) looking to try some game dev for the first time. Great video and love the emphasis on building tidy code / libs for re-use. Some random questions for you, how would you add a 3rd person controlled player to a tile system e.g. Factorio style player control? Does Unity have a Nuget style system? Also does Unity have enterprise options for collab for free e.g. TFS / Git style fork/branch/merge with auto-merge support i.e. flags code overlap with a Push / Pull, pipelines and unit test automation for CI/CD.
I created a system like this for my game except it doesn't use the grid system like that. It basically just rounds the vector coordinates from Camera.ScreenToWorldPoint to full values (1.0f, 2.0f etc) to "snap it" into a grid. I'm also using tilemap colliders to check the area beneath (some buildings can only be constructed on specific ground area and they can't be built on walls or other buildings. I'm also using raycasting to check if the area is a legal building space. I'm about to finish all my sprites for the buildings of my game. Just one more to go, but I had to check this video first to see how you are doing the building placement ':D
Yup that's pretty much the same method I used on the Freeform building system with some snapping on top
ruclips.net/video/EpMFOeOMInM/видео.html
It's a great simple system
Hello! Since I didn't see it in the playlist and was very confused about the newly-introduced GridXZ class, may I suggest you add the video about converting 2D systems to 3D into the playlist? ♥
It's just a swap from XY to XZ so I didn't make a dedicated video on that, I talked about it briefly here unitycodemonkey.com/video.php?v=3zxTigjJr24
Hey, ive been struggling with this as well.
If you download the project files, you can actually find the entire GridXZ class code over there.
I'm working on a 3D base building system, for my tutorial. So I came here to get inspiration.
@@Mikes-Code thank you I have been struggling the same issue.
I was 100% missing this peice after watching the videos.. Thanks for GridXZ
Thanks!👍🏾👍🏾
Amazing work!!!
The last part you completely missed to explain and show how you programmed. In the ghost script you suddenly have made the gridbuilding script to a singleton, without explaining that or how you make it a singleton for people who are new to that concept. The Onselectedchanged variable or whatever that is, came out of nowhere and finally the GetMouseWorldSnappedPosition function also out of nowhere. You should really explain these things or at least mention that you aren't gonna show this in the video cause this makes me feel like I've missed something but I've looked through the video several times and can't find that.
same
Keep going bro 😀
You saved my live! I tried to extend your previous version to do exactly what you describe here but couldn't get it to work. Thank you so much :-)
Btw: is there a way to modify the grid so I can create a level in the editor with it?
Thanks for the video. Any chance of seeing creating in-game level editor tutorial sometime?
This could definitely be used as a level editor, combine it with a Save Load system ruclips.net/video/6uMFEM-napE/видео.html
and you can even easily share levels.
You can write extension method for Dir enum for clarity. That way you can write "dir = dir.Next();". Great video!
That's a great tip! I definitely should use extension methods more often
Hello CodeMonkey, I followed your tutorial until you placed your first building at around 5:30. It did not work for me as expected, because the building was always placed in the first cell. After quick debugging I found out that the Raycast always returned a Vector3 zero, so that explains why the building was always placed in the first cell. I don't see you using any colliders on your cell, but as soon as i added colliders to my cells it started working. So I am wondering how did you make it work without using colliders on your cells? Could you please explain that? Thank you! :)
Really came in clutch for my RTS game! Only issue that i have, how to invalidate positions on the grid where the terrain is too steep bu build on. Gotta figure it out somehow. Thanks for the tutorial!
Thanks!
You could do a Raycast to sample multiple points within a grid position and check the total height difference between them.
@@CodeMonkeyUnity That is an awesome idea! Will definetely check it out, thanks a lot
Hey CodeMonkey! Loving this video series so far. I think I'm missing something, but how are you able to "spawn/instantiate" what looks like building prefabs using "Transform"- more specifically, at 4:04. Thanks!
Transform and GameObject are pretty interchangeable, you can spawn the entire prefab with either reference. Every Transform is always attached to a Game Object, and every Game Object always has a Transform component.
@@CodeMonkeyUnity Interesting, I've not seen this done yet! Thanks for the explanation :)
27:10 - do you have a separate video about this approach?
This looks amazing! Is that system also recommended when you wanna create a grid with a lot of tiles(like over 90k tiles?) like similar to rimworld.
You would need a system to manage multiple grids instead of having a single huge giant grid but yes this system can work for that.
amazing work!
Hi i just wanted to know if we could have the unity package of this tutorial.
There's a link in the description
@@CodeMonkeyUnity I clicked on the link but it gives me an error when I try to download the file.
@@zx.hash.r You need to log in
Thanks for this
Hi, thanks for all your content! It helps me a lot - not only with Unity, but also with the "game dev thinking"! :) I have a question related to this. What will be the approach, when the terrain will be not flat? It will be easy to implement the different terrain heights? Thanks for hint :)
The simplest approach would be to keep the underlying Grid flat and only snap the placed objects to the terrain.
But if you need the Grid to match with the terrain perfectly by area then that's much more complicated, not exactly sure how you could do that, probably need to take the Terrain mesh and make a simplified Grid mesh while keeping the rough terrain shape.
Fix for those who are getting null references for the CanBuild() check for multi-grid buildings along the edges of the grid and couldn't fix it themselves:
bool canBuild = true;
foreach (Vector2Int gridPosition in gridPositionList)
{
//this is the fix
if (grid.GetGridObject(gridPosition.x, gridPosition.y) != null)
{
if (!grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild())
{
canBuild = false;
break;
}
}
else
{
canBuild = false;
break;
}
}
all you have to do is to check if grid tile returns GirdObject, and if it doesn't then you can't build there
Amazingly good tutorial. Just a question. When you implement the destruction why not just store the vector2 list used when instantiating. On destruction you just access the list from the transform you allready have and delet the object and then clear the transoform. I find the solution you provide much more complicated.
So essentially instead of reverse enginering the Vector2 List just Store it.
Hi Code Monkey, I think the "ghost" part of the video is missing... I switched the prefabs and the alpha/transparency/ghost is not working
Are you using the renderer object from the files? That's what handles the visual
Much appreciated !
I know you get some flak for the way these tutorials are structured but I love them, filling in the gaps and creating my own solutions is so much better than just mindlessly copy pasting the whole thing
Thanks! It's hard to make everyone happy while also making free videos and satisfying the RUclips algorithm. I'd love to one day take everything I made in this Grid System and make a nice easy to follow step by step course
Question:
Are you using raycast to detect mouse position ?
cause i remember in the original Grid system video you converted the mouse Screen Position but i dont think that would work for the z-plane isn't ?
Edit: Nevermind you answered this question @5:16 , no idea how i missed it the first time i watched this lol
Yup the 3D method is indeed using a Raycast
How did you go into the grid class ? Was that in the other video?
Yes I made it over the course of several previous videos, it's not the same as the built-in Unity Grid class unitycodemonkey.com/search.php?q=grid
@@CodeMonkeyUnity ok got it !
I have multiple questions:
Is the "Heat Map" scripts required to make this work
The Generics from "Powerful Generics" required/helpful to use
If i wanted to put this into a 2D game, is all i have to do is put 2D instead of 3D and Y instead of Z
Great video/series. Really helpful!
Having some trouble with grid out-of-bounds cases, both in object placement and for the ghost visual. Trying some things without success. Hopefully I'll get it working correctly eventually.
In the first, I get a null reference error for object reference not being set on an instance of the object. I've seen some comments about it but can't get it working right.
In the second, the ghost visual is visible and its transform follows the mouse outside the grid. I need to disable it when outside, and re-enable it when inside the grid. Not sure if the same happens in the video's implementation since the topic isn't covered a lot in it.
To avoid null refs the simple solution is to always validate the position, just a simple check if x,y is > 0,0 and < width,height
I don't remember how I made it in this demo but yup that's one option, let it follow hte mouse exactly if there's no grid position underneath or leave the ghost on the last valid grid position.
Although if you were to use this in a complete game then chances are the play area is much bigger than what I used in the demo so going out of bounds is less of an issue.
Hey, I love this tutorial and definitely could use it in a project in the future. But, I have a suggestion for a future video that could expand upon the grid system. I wonder if there is a way to take the grid and use it to generate terrain and buildings on a map. I’m thinking of a system like ACNH, where an island is a general shape but that the game would randomly generate all the terrain features on a grid inside the blinds if the island so each time you played you got a new island layout (which can be customized if desired later in the game). I’m sure it’s probably a huge ask, but I think it would be a great addition onto the series of grid related tutorials you have.
Using this for a terrain system would definitely be interesting. Usually random generation is made more with Perlin noise but you could apply this system in the end and do something interesting with it.
I'll look into it, thanks!
5:00 Why to use Transform to store and instanciate the prefab instead of GameObject?
Mainly personal preference. If you call Instantiate(); on a Transform you get a Transform and if you call it on a Game Object you get a Game Object
All Game Objects have Transforms and all Transforms are attached to Game Object so both those types are pretty interchangeable.
Cool tutorial!
Could this be implemented into your Hexagrid System tutorials as well?
Yup! I converted this system to hex here ruclips.net/video/0nXmuJuWS8I/видео.html
A lot of the logic is the same, just some different math
Hello, so I have some advice for those using unity version 2022+ just incase you having some issues, 1 -- when downloading CM's assets for any of his videos if you already have script's with the same naming structures both Unity and Visual studio are going to throw a fit, simple fix is to use /* above the using statement's and */ at the very last line of the CM script's, this clear's most of the issues in the project for the script's and still allows you to use them as reference when solving issues, 2 - if you import the scene it can some times have issues that I haven't found a fix for, best to not import that and simply rebuild the scene normally doesn't take very long, also don't import anything that say's URP or Setting's for some reason this causes issue's I'm not sure why Better to just import URP into your project or, start a project already setup for URP, 3- best way to add your own prefab's to replace pink/purple issue with visual's is to use the same structure as CM, by adding a prefab with the logic, then having the script logic instantiate the visual of your choice as a child of the parent(what the logic script is attached too), then changing what's needed in your script's to fix any other issues that are still persistent, as for an easy ghost prefab can just have the material set to 50% or so transparency and then have it set back with code after the prefab as been placed/Instantiated(this worked for me, might try it urself), 4 don't forget to also download and import CM's util's, or build some of your own with the same naming structure to prevent having to change a ton of code.. if u have other issues after doing this I apologize as I'm still new to a lot of this as well and not sure how to help, Sorry this was a mouth full! Ps. CM in the part of this video where you check to see if a building is occupying multiple point's on the grid, is there any advice you can give if I wanted to check if a unique oddly shaped object where to be rotated and which part's of the grid where at the closes co-ordinance and then make the grid with a value of Range(x etc.) or a bool of T/F change the underlying grid values, I've been trying some ideas on my own to get this to work with no success so far, any advice would be helpful. With that said, Thank you for your video's as they have been a great source of learning both programing and game development as well as clean coding technics. I look forward to continuing to watch and learn, Keep it up your doing Great! (I'm using unity 2022 3d URP project setup and have had no issues after fixing the above Hope this helps!)
Thanks again for a great video. One thing I would like to understand is how you size your tiles to match with the grid? For example, if I have a path that I am trying to lay out, how are they sized properly for a grid that is larger than the unity unit?
You just scale the visuals/prefabs or modify the grid cellSize to match what you have in the visuals/prefabs
@@CodeMonkeyUnity thanks for the quick reply! Scaling the visuals up led to blurry images but I may just need better images. Also when creating the backgrounds for paths and such it was hard to place them properly without the help of the grid in the scene
@@CodeMonkeyUnity Ah that completely makes sense now that I've had a chance to check it out. Once I added the 2D Tilemap I simply scaled it to match the grid size (10 in my case), and the tiles from the palette naturally lined up without any fuss. Thanks so much! And I purchased your Builder course today too given how helpful you've been! Thanks!
I am having trouble getting started with this. I went back and watched the first video, and now this one doesn't make sense really. I downloaded the files and looked in there and can't find a GridXZ script. Was that in a different video? I am also getting some errors.
This playlist isn't designed as a step-by-step course, I've just been building systems and expanding upon it over time, so there are changes between the videos. Watch the whole playlist to learn how the system works and then look in the code yourself to fill in the gaps.
What errors do you see?
@@CodeMonkeyUnity The errors I think I saw were things about the generics and how GridXZ wasn't a thing. There might have been two more but I can't remember.
Hey sir , please make a video on how to upgrade buildings for a given time and when time is completed we can see the new upgraded building
for some reason when i place a building it only places on the x part of the grid and doesn't go on the z part. this occurred after around 6:30 when implementing the instantiation on the grid and not just anywhere you click
nevermind i found the issue. it was with the gridxz script as i was working from the first video one the playlist making the grid system and when altering the class to the gridz i missed one single ".y" when changing them to lol
You should update your grid video to include 3d (x , z) alignment . i see you do it here but even though i spend over 2 hours after watching the grid video searching your other videos about where you did that i didn't find it
It's really just swapping XY for XZ, all the logic is exactly the same ruclips.net/video/3zxTigjJr24/видео.html
Both Grids are included in the project files for this video, you can download and compare them
@@CodeMonkeyUnity nice thanks !!
Hello Sr, I wanted your opinion on this:
Say that you had this Grid class, but adapted to work with 3 dimensions "int[ , , ]", to make minecraft let's say.
I was thinking that you would need a class to store all the chunks in the scene, but since minecraft it's practically infinite, you probably don't want to do that.
How do you save each chunk? I know that you would have to save them separetly, like, the easiest solution that I can think of it's make a json out of each chunk and when writing this to a file, name the file with the coordinates of the chunk so you can get it back easily. The think with this, is that I know that minecraft saves all of the stuff in one single file, my question is how? How do you make each chunk a string and the put them all togheter? string.joint does this, but then how do you get the ecxact chunk that you want back? string.split get's you a list of arrays, and you could place it all in a order where you could track your chunks back, but still you have to get all your chunks at once from file to string, and Idk, I was wondering if there's a solution that I'm not thinking of...
Turning this into a Voxel System is definitely something I'd like to explore but haven't done any research yet. The idea would indeed be pretty much like that, split the world into chunks and make a save system to save each chunk.
JSON would indeed work since it's just a string, I would make a main save file and in that main save file I would store a string[] to store all the JSON strings for all the chunks.
Then each chunk save JSON knows where it's placed and what buildings/blocks are on it.
I made a save file a long time ago for a Highscore table, it's pretty much exactly the same thing except saving world chunks instead of highscore entries unitycodemonkey.com/video.php?v=iAbaqGYdnyI
This is Really Awesome :D Next how to save every thing and also Load?
This gives me idea of Track Bulder inside my racing game, sort of like parkEditor in Thps 2-4, or TrackMania :D
if only i had money to hire you :D
Yup you could combine this with the Save system I made previously ruclips.net/video/6uMFEM-napE/видео.html
and you'd be able to save the grid with all the buildings and even share the save file with friends.
@@CodeMonkeyUnity oh i see That`s cool :D Awesome, i didnt knwo you had made a save&load video, ir i had forgotten it hehe :)
Hi CodeMonkey, very good video by the way but even having understood the subject as a whole, I can't figure out how to make sure that I already have a structure placed on the grid and make it possible to move the grid during that the game is running and not just create it at startup? Your content is always so refreshing and a source of motivation, good luck for the next :)
Quite late answer but...
His grid system have a Vector for the origin position, if i remember well (there is couple years i don't use unity anymore) i used to change the grid origin to move it if needed.
hello code monkey, I have a bug, every time I click out side the grid the scene stop.
and I have a question, how to check continuously if the player can build or not, cuz right now it just check every time I click.
Sounds like an error because you're clicking out of bounds, you need to add checks to the position
You can run the CanBuild logic on every Update
Hey, I'm having the problem of needing to save the grid layout, but it can't convert the type array to a class array.
How do I save the grid position?
How to do Save system in this project. :(
The grid system not work in my Custon Save :(
I Have to slow the video down to try to keep up with you but my efforts are use less..lol I’m. Not able to understand what’s happening and how it’s happening... but I’m learning and this is by far one of the best videos I have found to try go threw the code on... thanks..
You can also download the project files to inspect the source code better, combine that with watching the video and it will be easier to understand
Render Objects doesn't exist in the current project files. How is it call now?
I hope to be able to contribute with your channel through Patreon soon.
There's no word to describe how I enjoy and learn from your videos!
Thank you!
Thanks! I'm glad you find the videos helpful!
5 star content!!!
Very nice video! Could you make a follow up and explain how you could make a more-dimensional grid, for example for multi story houses? That would be very nice and awesome.
You can make multiple Grid Systems for each height level, that's what I did for my house building system unitycodemonkey.com/video.php?v=Cdcn6uK9gPo
By any chance, do you have a starting point tip on how to move the grid while playing the game? Like in the Update() method?
If not, I'm gonna try to figure it out myself somehow. Thanks anyway for the great grid system, you're such a help.
Please?
Hi, thanks for the video.
where can I find only the utils and the scripts that you dont show on the video? I dont want the entire project but on most of the script i cant use because I miss parts like the scriptble object
You can download the project, import it to a separate project and then take only the parts you want onto your own project
Or just the utilities are here unitycodemonkey.com/utils.php
Where can I learn to code the XZ Grid. I can only find a grid for XY
You just have to swap the XY logic for XZ. It's a very simple process so I didn't cover it in a dedicated video, you can look at both scripts side by side ruclips.net/video/3zxTigjJr24/видео.html
@@CodeMonkeyUnity wow thank you. I didn’t expect a response from anyone let alone you! I got confused as I saw things like TGridObject which I do not recognise. I will try to figure it out now! Thank you!
Thank you so much! I understand how to continue on with my game now!
Also. With downloading project files. Do you need to pay. Or are they just not working. As if I try to download them to compare code or something like that it fails to download
@@CodingWithBen Maybe the server went down for a bit, try downloading again, there's no need to pay
TGridObject is a Generic ruclips.net/video/8jrAWtI8RXg/видео.html
Do you need to have done all the grid system tutorials before this one to full understand it or just the first one?
By watching just the first one you'll get a rough idea of how it all works