Awesome Grid Building System! (City Builder, RTS, Factorio, Survival)

Поделиться
HTML-код
  • Опубликовано: 17 янв 2025

Комментарии • 643

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 года назад +28

    🌐 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?

    • @kyleevans4830
      @kyleevans4830 3 года назад

      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!

    • @dieweltentdecker5878
      @dieweltentdecker5878 3 года назад

      I dont find the building sound in the Unity package?

    • @ludvigerdmann3352
      @ludvigerdmann3352 3 года назад

      My unity protect says that it cant find the GridBuildingSystem3D file

    • @peterbelanger4094
      @peterbelanger4094 3 года назад

      (Using Unity 2020.3.12f1).....Started clean, new project, tried to import the unitypackage, and there are 57 errors.
      Am I missing some dependencies?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      @@peterbelanger4094 What errors? Make sure you're using URP and Cinemachine

  • @youtuber9991
    @youtuber9991 3 года назад +302

    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.

    • @skyswimsky1994
      @skyswimsky1994 2 года назад +17

      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

    • @あれくす
      @あれくす 2 года назад +18

      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.

    • @bigadingm5908
      @bigadingm5908 2 года назад +5

      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)

    • @bigadingm5908
      @bigadingm5908 2 года назад +3

      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

    • @carroll6
      @carroll6 2 года назад

      me too, it's hard to follow. Goes so fast.

  • @Gredran
    @Gredran 4 года назад +37

    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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +3

      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!

  • @izzet8635
    @izzet8635 4 года назад +54

    OMG SERIOUSLY, THIS WAS EXACTLY WHAT I NEEDED AND IT JUST CAME OUT. sorry for yelling xD

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +8

      I'M GLAD YOU'RE EXCITED! Thanks!

    • @GhostSlayerYT
      @GhostSlayerYT 3 года назад +1

      @@CodeMonkeyUnity is there a basic tutorial of making a game?
      cause I started learning a week or two ago

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +3

      @@GhostSlayerYT I covered Unity Basics here ruclips.net/video/E6A4WvsDeLE/видео.html
      And C# Basics here ruclips.net/video/IFayQioG71A/видео.html

    • @GhostSlayerYT
      @GhostSlayerYT 3 года назад +3

      @@CodeMonkeyUnity oh thanks
      And c# means the scripting part right?

    • @alxoseal517
      @alxoseal517 3 года назад +1

      @@GhostSlayerYT Yes

  • @ObsessiveGames
    @ObsessiveGames 3 года назад +10

    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 !

  • @diskerus
    @diskerus 4 года назад +4

    It's fantastic... that's what I was searching so long. Thank you, Code Monkey. You deserve millions subscribers as Brackeys

  • @dartutorials7859
    @dartutorials7859 3 года назад +8

    NIce finally i can build my own city 👍👍 I might upload the city that I built with this tut

  • @alaslipknot
    @alaslipknot 3 года назад +6

    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!

  • @sundarakrishnann8242
    @sundarakrishnann8242 4 года назад +7

    Glad to see that many of your new videos are getting better views!😜

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Thanks! Yeah it seems people have enjoyed the last few videos!

  • @subliminalcastillo2126
    @subliminalcastillo2126 4 года назад +52

    Code Monkey coming in clutch with the tutorials everyone wants.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +4

      Thanks! I try to give the people what they want!

    • @Grinwa
      @Grinwa 3 года назад

      @@CodeMonkeyUnity yea u r awesome tnks a lot

  • @acez28
    @acez28 11 месяцев назад +2

    3 years later...thank you Code monkey... you don't know the length of good you have done 👍

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  11 месяцев назад +1

      heh I'm glad the video helped you! I also love how some tutorials are somewhat timeless

  • @StellarMirage
    @StellarMirage 2 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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

  • @leonn5148
    @leonn5148 3 года назад +1

    Oh thank you so much!!!! I was struggling to find something similar to this for weeks. Cheers!!

  • @donkeymonkey4435
    @donkeymonkey4435 4 года назад +1

    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

  • @PyRubier
    @PyRubier 4 года назад +20

    I have a question. Has anyone ever told you that you are a FUCKING BOSS? :D

  • @ChrisNoeth
    @ChrisNoeth 2 года назад +1

    This is probably one of the most useful tutorials for starting a cool game system ever! THANK YOU! :)

  • @ajogar
    @ajogar 3 года назад

    you don't know how long i've been looking for this

  • @Fragler01
    @Fragler01 3 года назад +1

    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 :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +2

      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!

    • @Fragler01
      @Fragler01 2 года назад

      @@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.

  • @alejandro6544
    @alejandro6544 2 года назад +2

    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?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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

  • @TomMcDonaldGames
    @TomMcDonaldGames 3 года назад +1

    Great Tutorial. Thanks for putting this together..

  • @CodemasterJamal
    @CodemasterJamal 3 года назад

    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.

  • @jean-michel.houbre
    @jean-michel.houbre 4 года назад +2

    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.

  • @Setanta93
    @Setanta93 4 года назад

    Looking forward to your next game, I've 100%-ed almost every game you've released!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      That's awesome to hear, I'm glad you liked them! Thanks!

  • @toprogress
    @toprogress Год назад

    Sweet and quick tutorial, perfect to acquire experience in coding. Thanks for the knowledge!

  • @honzakusy
    @honzakusy 3 года назад

    Great video! It really helped me with the implementation of my game! Nice work 👏

  • @oguzhanozcelik8466
    @oguzhanozcelik8466 3 года назад

    Awesome tutorials!!! Keep up the good work!

  • @leonardo6631
    @leonardo6631 4 года назад +2

    Amazing video 😁

  • @BimzyDev
    @BimzyDev 4 года назад

    Good stuff, thanks for the tutorial! 😆

  • @guridoraccoon6375
    @guridoraccoon6375 4 года назад

    omg ive been building my grid system these days. perfect!

  • @Pandahero-ce9fi
    @Pandahero-ce9fi 4 года назад +4

    is there any chance that we get a conveyor tutorial that goes along with this?

    • @Crankpie
      @Crankpie 4 года назад

      I'm waiting too !

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      I am working on that Factory game and, while not a full tutorial, I will definitely mention how the conveyor belts work

    • @axl2858
      @axl2858 4 года назад

      ​@@CodeMonkeyUnity I hope that's a type of project that you could share it's source code

  • @UmeshRajaramKandekar
    @UmeshRajaramKandekar 3 года назад +1

    Awesome Sir 🔥🔥

  • @Rivera-D
    @Rivera-D 4 года назад

    Wahhhhhh awesome, this is what i need. Thanks 🔥❤️

  • @Sakros
    @Sakros 3 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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

  • @vmmi8215
    @vmmi8215 3 года назад

    Love this video so much 👍👍

  • @dererzherzog
    @dererzherzog 3 года назад

    Yoy're the best! Thank you so much for sharing your knowledge with us!

  • @omyb
    @omyb 2 года назад +1

    Hi! Really great video! How would you handle L shaped buildings? Maybe an idea for the next video :)

  • @AndyLukito
    @AndyLukito 4 года назад

    Awesome!

  • @aditkumar4644
    @aditkumar4644 3 года назад +1

    I literally needed it like right now thanks code monkey

  • @amberlewis012
    @amberlewis012 3 года назад +1

    Holy chicken wings this tutorial was uploaded at the perfect time!

  • @Syvies
    @Syvies Год назад

    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!

  • @ssj3mohan
    @ssj3mohan 4 года назад

    I love your tutorials .

  • @TheGhost_179
    @TheGhost_179 4 года назад +2

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      That would be interesting, I'd definitely love to do some more RTS tutorials

    • @Berndr
      @Berndr 3 года назад

      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

  • @user-jt7bf2fo5m
    @user-jt7bf2fo5m 3 года назад +2

    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!

  • @easyanton7952
    @easyanton7952 4 года назад

    Perfect! Thank you very much!
    You quickly showed that you make a game, with conveyor belts.
    Will there be a tutorial with them?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      I am working on a more showcase video rather than a step-by-step tutorial but yes I will mention how the belts work

  • @tiwrun
    @tiwrun 4 года назад

    Helps a lot thanks

  • @feliscape
    @feliscape 2 года назад +1

    Where does the GridXZ come from? I watched the tutorials but I didn't see it anywhere.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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

  • @roshanthapa1297
    @roshanthapa1297 4 года назад +4

    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 😅

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      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

  • @nathanav1634
    @nathanav1634 3 месяца назад

    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.

  • @oatcube3961
    @oatcube3961 4 года назад +1

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      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

  • @W0rldbuilder
    @W0rldbuilder 2 года назад +2

    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? ♥

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      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

    • @Mikes-Code
      @Mikes-Code 2 года назад +2

      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.

    • @lunasylphhh
      @lunasylphhh Год назад

      @@Mikes-Code thank you I have been struggling the same issue.

    • @jamaismejamaisme6196
      @jamaismejamaisme6196 5 месяцев назад

      I was 100% missing this peice after watching the videos.. Thanks for GridXZ

  • @BeerfootBandit
    @BeerfootBandit 4 года назад

    Thanks!👍🏾👍🏾

  • @HugoMesquitaO
    @HugoMesquitaO 3 года назад

    Amazing work!!!

  • @augustlewen
    @augustlewen 3 года назад +5

    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.

  • @THEKALMED
    @THEKALMED 4 года назад

    Keep going bro 😀

  • @tweetymr
    @tweetymr 3 года назад

    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 :-)

    • @tweetymr
      @tweetymr 3 года назад

      Btw: is there a way to modify the grid so I can create a level in the editor with it?

  • @teemuleppa3347
    @teemuleppa3347 4 года назад +1

    Thanks for the video. Any chance of seeing creating in-game level editor tutorial sometime?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      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.

  • @zaimatsu
    @zaimatsu 3 года назад

    You can write extension method for Dir enum for clarity. That way you can write "dir = dir.Next();". Great video!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      That's a great tip! I definitely should use extension methods more often

  • @agonyzx
    @agonyzx 7 месяцев назад

    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! :)

  • @selmansavas586
    @selmansavas586 3 года назад +2

    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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Thanks!
      You could do a Raycast to sample multiple points within a grid position and check the total height difference between them.

    • @selmansavas586
      @selmansavas586 3 года назад

      @@CodeMonkeyUnity That is an awesome idea! Will definetely check it out, thanks a lot

  • @heyitsapogee
    @heyitsapogee 3 года назад

    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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +2

      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.

    • @heyitsapogee
      @heyitsapogee 3 года назад

      @@CodeMonkeyUnity Interesting, I've not seen this done yet! Thanks for the explanation :)

  • @tomtomkowski7653
    @tomtomkowski7653 3 года назад

    27:10 - do you have a separate video about this approach?

  • @GameReleaseENG
    @GameReleaseENG 3 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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.

  • @MikoGot
    @MikoGot 3 года назад

    amazing work!

  • @zx.hash.r
    @zx.hash.r 3 года назад +1

    Hi i just wanted to know if we could have the unity package of this tutorial.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      There's a link in the description

    • @zx.hash.r
      @zx.hash.r 3 года назад

      @@CodeMonkeyUnity I clicked on the link but it gives me an error when I try to download the file.

    • @samuelh2005.
      @samuelh2005. 3 года назад

      @@zx.hash.r You need to log in

  • @Updates_
    @Updates_ 4 года назад

    Thanks for this

  •  3 года назад

    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 :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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.

  • @zbyszekkiebasa906
    @zbyszekkiebasa906 3 года назад +3

    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

  • @odatas
    @odatas 3 года назад +1

    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.

  • @RodAires
    @RodAires 3 года назад +1

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Are you using the renderer object from the files? That's what handles the visual

  • @_CloudyBunny
    @_CloudyBunny 4 года назад

    Much appreciated !

  • @Notllamalord
    @Notllamalord Год назад +1

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

  • @alaslipknot
    @alaslipknot 3 года назад

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      Yup the 3D method is indeed using a Raycast

  • @codrfheverything2954
    @codrfheverything2954 Год назад

    How did you go into the grid class ? Was that in the other video?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

    • @codrfheverything2954
      @codrfheverything2954 Год назад

      @@CodeMonkeyUnity ok got it !

  • @danielspringer2610
    @danielspringer2610 4 месяца назад +1

    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

  • @ignallacay
    @ignallacay 2 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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.

  • @DakotaRileyMedia
    @DakotaRileyMedia 4 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      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!

  • @darcking99
    @darcking99 2 года назад

    5:00 Why to use Transform to store and instanciate the prefab instead of GameObject?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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.

  • @AstralZenithal
    @AstralZenithal 4 года назад

    Cool tutorial!

  • @Jebbles1
    @Jebbles1 8 месяцев назад

    Could this be implemented into your Hexagrid System tutorials as well?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 месяцев назад +1

      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

  • @Surenian
    @Surenian Год назад

    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!)

  • @MarkMcArthey
    @MarkMcArthey Год назад

    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
      @CodeMonkeyUnity  Год назад +1

      You just scale the visuals/prefabs or modify the grid cellSize to match what you have in the visuals/prefabs

    • @MarkMcArthey
      @MarkMcArthey Год назад

      @@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

    • @MarkMcArthey
      @MarkMcArthey Год назад

      @@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!

  • @ludoremstudios
    @ludoremstudios 3 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      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?

    • @ludoremstudios
      @ludoremstudios 3 года назад +1

      @@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.

  • @idance_div
    @idance_div Год назад

    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

  • @maow9240
    @maow9240 3 года назад

    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

    • @maow9240
      @maow9240 3 года назад

      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

  • @Rook1e0ne
    @Rook1e0ne 4 года назад +2

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      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

    • @Rook1e0ne
      @Rook1e0ne 3 года назад

      @@CodeMonkeyUnity nice thanks !!

  • @darcking99
    @darcking99 2 года назад +2

    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...

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      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

  • @StigDesign
    @StigDesign 4 года назад

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      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.

    • @StigDesign
      @StigDesign 4 года назад

      @@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 :)

  • @antsevestre
    @antsevestre Год назад

    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 :)

    • @Mikael._
      @Mikael._ Год назад

      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.

  • @AmgedAlfakih
    @AmgedAlfakih 3 года назад +1

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      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

  • @PurplySkye
    @PurplySkye 3 года назад

    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?

  • @solecito69
    @solecito69 3 года назад

    How to do Save system in this project. :(
    The grid system not work in my Custon Save :(

  • @myownthoughts969
    @myownthoughts969 3 года назад

    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..

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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

  • @franciscojaviergraciasanti18
    @franciscojaviergraciasanti18 2 года назад

    Render Objects doesn't exist in the current project files. How is it call now?

  • @magostinhojr
    @magostinhojr 3 года назад

    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!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      Thanks! I'm glad you find the videos helpful!

  • @shivamprajapati6839
    @shivamprajapati6839 4 года назад +1

    5 star content!!!

  • @disobedientdolphin
    @disobedientdolphin 2 года назад

    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.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      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

  • @lukaspaver
    @lukaspaver 6 месяцев назад

    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.

  • @NoamRiahi-v6j
    @NoamRiahi-v6j Год назад

    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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      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

  • @CodingWithBen
    @CodingWithBen 3 года назад

    Where can I learn to code the XZ Grid. I can only find a grid for XY

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      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

    • @CodingWithBen
      @CodingWithBen 3 года назад

      @@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!

    • @CodingWithBen
      @CodingWithBen 3 года назад

      Thank you so much! I understand how to continue on with my game now!

    • @CodingWithBen
      @CodingWithBen 3 года назад

      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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      @@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

  • @jwalkaz6097
    @jwalkaz6097 3 года назад

    Do you need to have done all the grid system tutorials before this one to full understand it or just the first one?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      By watching just the first one you'll get a rough idea of how it all works