Procedurally Generating A Hexagon Grid in Unity

Sdílet
Vložit
  • čas přidán 28. 08. 2024

Komentáře • 218

  • @NachitenRemix
    @NachitenRemix Před 2 lety +253

    Hexagon is the bestagon.

  • @stonefreak5763
    @stonefreak5763 Před 2 lety +92

    Hint: If u want to stay in 2D, then the Grid Component in Unity has an option for exactly that.

    • @AGreatTsunami
      @AGreatTsunami Před 2 lety +3

      And one can always extrapolate a tilemap into 3D objects~

    • @3nertia
      @3nertia Před 2 lety +8

      @@AGreatTsunami Wait, what? Would you happen to know of a video or article detailing what you mentioned?

    • @NominativoUnivoco
      @NominativoUnivoco Před 2 lety +3

      However, those hexagons are not accurate

    • @vinhnghiang1273
      @vinhnghiang1273 Před rokem +4

      what is the game at 0:47 ?

    • @mcfnord
      @mcfnord Před rokem

      @@NominativoUnivoco Why aren't the Grid Component hexes inaccurate? I have a game that needs hex grid

  • @nj5374
    @nj5374 Před 2 lety +11

    I'm a massive beginner so most of this went way over my head but this has inspired me to learn to use the mesh renderer by rendering some shapes procedurally - cheers!!

  • @AliveNotDeadmund
    @AliveNotDeadmund Před rokem +20

    For anyone with a null error when you go to render the first hex, make sure you update the return on CreateFace() to return new Face(vertices, triangles, uvs); because he initially writes it as 'return Face()' and then later amends it.
    Hope that helps!

    • @Kvn...
      @Kvn... Před rokem

      Hi, can you check my code, i thing ive done big wrong :8 nothing works

    • @rickbeniers667
      @rickbeniers667 Před rokem

      thanks for the comment I had missed him rewritting that part haha

  • @bakerfx4968
    @bakerfx4968 Před 2 lety +4

    My face lit up when I saw you had a new video. It was amazing as always! Thanks dude

  • @mrlucky974
    @mrlucky974 Před 2 lety +9

    YES ! Your videos are so great, and this one did not disappoint.
    Hexagons are the bestagons...

  • @Island54Games
    @Island54Games Před 2 lety +33

    Nice stuff. I just started working on hexagons for my own game literally hours before this video came out.
    One thing I strongly suggest is that you consider using axial or cubic coordinates instead of offset coordinates. While the coordinates aren't quite as intuitive at first, the maths gets *much* simpler. In your coordinate conversions for example, you get rid of all those odd/even conditionals.

    • @Nanukimo
      @Nanukimo Před 2 lety +2

      Is It Possible You Can Show How To Use Axial instead of Offset coordinate system?

  • @nightfox4013
    @nightfox4013 Před 2 lety +3

    This man deserves more attention, he’s so helpful.

  •  Před 2 lety +49

    Great video, as usual :-)
    Calculating Math.sqrt(3) is expensive, and because you are doing that several times, maybe you could create a constant with that value instead.

    • @td19xyz
      @td19xyz Před 2 lety +7

      Microsoft's CLR (the C# virtual machine) is able to optimize away the call to sqrt(3). It might not bother in debug builds though. That being said, you use sqrt(3) often enough `SQRT_3` might be more legible than `Math.sqrt(3)`

    • @Neph0
      @Neph0 Před 2 lety

      Allocating memory for the list at every tick probably has a much bigger performance impact here. But honestly is it such a big deal for a prototype like this? Nobody cares.

    • @Chris-lw5po
      @Chris-lw5po Před 2 lety +17

      @@Neph0 maybe newer game devs that don’t know the best practices and or why this wouldn’t scale well into a big project? I definitely am interested in hearing points like this…

    • @vinhnghiang1273
      @vinhnghiang1273 Před rokem

      what is the game at 0:47 ?

    • @brainwavestobinary
      @brainwavestobinary Před rokem +1

      @@vinhnghiang1273 That game is called, "Before we Leave".

  • @DmytroMomotov
    @DmytroMomotov Před 2 lety +8

    Good tutorial, it would be helpful to have visual representation of what code is doing side by side with current piece of code, otherwise it becomes a bit confusing

  • @3nertia
    @3nertia Před 2 lety +3

    Thank you so much! I searched and searched for this exact thing to no avail!

  • @Jonny01Boy
    @Jonny01Boy Před 2 lety +16

    Great video, I'm collecting tutorials like this to learn and also have a nice reference when building something similar. Appreciate the time you took to help the community.
    For those with an issue setting the material, I think there was a method setup in the HexRenderer that wasn't shown but you can use something like this if you need it.
    public void SetMaterial(Material newMaterial)
    {
    m_meshRenderer.material = newMaterial;
    }

    • @HaoaHaNa8513
      @HaoaHaNa8513 Před rokem +2

      I'm having trouble setting up the innersize, outersize, and height. Can you help?

    • @WildPork
      @WildPork Před rokem +1

      @@HaoaHaNa8513 [SerializeField] private Material material;
      [SerializeField] private float innerSize;
      [SerializeField] private float height;
      [SerializeField] private float outersize;
      then set them in the inspector

  • @lacata2570
    @lacata2570 Před 2 lety +4

    "Hexagons are the bestagons" felt like a CGP Grey easter egg

  • @cormo9058
    @cormo9058 Před 2 lety +5

    Great video, I do wish there was some diagrams showing what the different variables in the grid positioning function were doing coz I got very lost there but I'm glad you covered this topic - I've been wondering how to do this for ages

    • @GameDevGuide
      @GameDevGuide  Před 2 lety +2

      Check out the blog post linked in the description. It's full of helpful diagrams!

    • @meowsqueak
      @meowsqueak Před 2 lety +4

      @@GameDevGuide The blog post is great, however I feel your videos would be improved by a few diagrams, especially when explaining more algorithmic parts of the code, like looping around the faces. As it is, the videos are a little too "just write this and it'll work" rather than "this is how it works", and I think your obvious ability to communicate would be enhanced into one of teaching by this slight change in approach.

  • @boiimcfacto2364
    @boiimcfacto2364 Před 2 lety +2

    I was one of the first subscribers of Sebastian Lague - and I'm so glad I found another eloquent, entertaining Unity content creator in his early days.
    Trust me man, you're gonna make it big. Fantastic video.

  • @akmaludddin9281
    @akmaludddin9281 Před 4 měsíci +1

    i love how you show the code. i sub immediately! i hope all of you have fun and great days!

  • @ekzac
    @ekzac Před rokem

    You know the tutorial is good when you already know the solution, but it's funny to watch and see the things being built and explained. :)

  • @andrewwilson9052
    @andrewwilson9052 Před 2 lety

    I've just started trying to learn how to code for games and this Channel is just so cool. There's not a lot out there to help learn to make strategy games

  • @j.j.maverick9252
    @j.j.maverick9252 Před 2 lety +5

    Nice video, the mesh building is very clean. Surprised you didn’t use the axial/cube representation from redblob though, it simplifies everything related to selection which is a huge part of many hex games

  • @BlueHat1
    @BlueHat1 Před rokem +5

    Thank yiu for the tutorial, but it would be so much better if you explained what you were doing more and helped us visualize it. I was left a bit confused.

  • @rutchjohnson
    @rutchjohnson Před 2 lety +12

    For those getting an error when first rendering your hex it might be related to the OnValidate method. I had to check for not null on m_mesh. Example: if(Application.isPlaying && m_mesh != null)

    • @SpankytheEvilMo
      @SpankytheEvilMo Před 2 lety +1

      I typed up the code seen in the video but Unity is giving me a bunch of errors. Is there something that I should be doing that's not being covered?

    • @rutchjohnson
      @rutchjohnson Před 2 lety

      @@SpankytheEvilMo I've only completed generating the hex. The code in the video works. I haven't started coding the grid yet.

    • @SpankytheEvilMo
      @SpankytheEvilMo Před 2 lety

      @@rutchjohnson Huh, then I wonder what I'm doing wrong. Researching, it seems that this may be a custom editor and I missed that fact.

    • @rutchjohnson
      @rutchjohnson Před 2 lety

      @@SpankytheEvilMo I’m not using a custom editor.

    • @dislexei
      @dislexei Před rokem +1

      Thank you! Been debugging that one for the last couple of hours :)

  • @simoncodrington
    @simoncodrington Před 2 lety +1

    Another great video mate cheers. Can't wait to see what you come up with next!

  • @blainewordly9134
    @blainewordly9134 Před 2 lety +1

    great tutorial can't wait for the next one on hexagonal grids!

  • @HereBeCush
    @HereBeCush Před 2 lety +5

    Great tutorial! Absolutely loved it 👏🏻
    I found in my case that the hexagons were disappearing when they got near the edge of the screen. I fixed this by setting the size of mesh.bounds in the DrawMesh function (center being Vector3.zero and the size being a slightly different Vector3 depending on whether the hex is flat-topped or not)
    The full code I added:
    Vector3 boundSize = new Vector3( outerSize, height, outerSize );
    if( isFlatTopped ){
    boundSize.x *= 2f;
    boundSize.z *= 1.75f;
    }else{
    boundSize.x *= 1.75f;
    boundSize.z *= 2f;
    }
    mesh.bounds = new Bounds( Vector3.zero, boundSize );

    • @vinhnghiang1273
      @vinhnghiang1273 Před rokem

      what is the game at 0:47 ?

    • @GregX999
      @GregX999 Před rokem +2

      You can also just use "mesh.RecalculateBounds()" right after "mesh.RecalculateNormals()" in the "CombineFaces()" method.

    • @HereBeCush
      @HereBeCush Před rokem

      @@GregX999 Awesome, didn't know this - thanks!

  • @mementomori7160
    @mementomori7160 Před 2 lety +2

    0:22 And in my, hexagons are... bestagons
    Edit 1:
    0:51 YES my brother!
    Also I've already worked on it for a while, there is a simple way to make hexagon based coordinate system, also allows for making layers of hexagon tiled planes, I guess you'll show it on one of other methods soon

  • @PhaygeWoW
    @PhaygeWoW Před 9 měsíci +2

    I'm on Unity 2022.3.13f1 and cannot get even the base mesh to render... I have no idea what's going wrong. Has anyone else encountered this?

  • @meowsqueak
    @meowsqueak Před 2 lety +3

    Great video, looking forward to the next one. BTW one should NOT call DrawMesh() in OnValidate() because this creates a horrible race condition, as OnValidate() can be called before Awake() resulting in numerous null dereference attempts. Instead, OnValidate() can set a flag that Update() checks before calling DrawMesh(), or Awake() can set a flag that OnValidate() checks before calling DrawMesh(). I favour the former because the Unity docs for OnValidate() actually say that this function should not be used to create objects. It's only meant for validating existing data.

    • @OBrownie_
      @OBrownie_ Před rokem

      Bruh, i'm getting this error, and i don't know how to fix it (i'm more than a noob in programming), can you write here the code correction please?

    • @meowsqueak
      @meowsqueak Před rokem +1

      @@OBrownie_ sorry I don't have the code any more - but from memory, instead of calling DrawMesh() in OnValidate(), just set a bool flag to true, and then in Update(), if the flag is true, then call DrawMesh(). This ensures that the mesh is only created in the Update phase, and never before Awake (which can happen sometimes because OnValidate() can be called before Awake() is). Hope this helps.

  • @dptgames2254
    @dptgames2254 Před rokem +3

    At 04:08 my script material just shows none and when I add it as a component it just says none for material and mesh, any one know where I'm going wrong? Are you supposed to add it as a component to something specific?

    • @phillypustudios
      @phillypustudios Před rokem

      You probably need to create a new GameObject (named "Hex") and add component > script (HexRenderer) to get to the next point in the video.

  • @mobilelast1715
    @mobilelast1715 Před 2 lety +3

    Great explanation. That Red Blob's hex-site you mentioned is indeed an excellent resource.
    Hex grid is actually a special case of the Voronoi diagram. Another curious pattern that all programmers should be aware of.

  • @Dranzer10HD
    @Dranzer10HD Před 2 lety

    I've found my new favourite gamedev channel! :D

  • @stephenkirby6788
    @stephenkirby6788 Před 2 lety +1

    I'm not using anything like this right now in my projects, but I watched it anyways. Very informative and great production value. Next level!

  • @jackpaice
    @jackpaice Před rokem +7

    Please make your code available on a repo so we don't have to spend 1h trying to figure out where we went wrong by copying manually.

  • @DevOverdrive
    @DevOverdrive Před 2 lety +1

    I love your videos. Please keep up the good work! Can you make a video on setting up a car traffic system or a raycast detection system.

  • @Ferenc-Racz
    @Ferenc-Racz Před 2 lety +1

    Thank you for your knowledge sharing. Subscribed and liked offcorse. :)

  • @Tasarran
    @Tasarran Před 2 lety +1

    Instant like for "Hexagons are the bestagons!"

  • @Rhanati
    @Rhanati Před 10 měsíci

    This is an awesome video, thank you for the explanation!

  • @weks
    @weks Před 2 lety

    Amazing stuff as always! Thanks for the content!

  • @TimurKOI
    @TimurKOI Před rokem

    Thank you very much for this video! For me it is too complicated at first look but again thank you for detailed explanation without useless waste of time! HUGE like and subscribe!

  • @jeshuanavarrogarcia
    @jeshuanavarrogarcia Před rokem

    Thanks, and waiting for the next video for thepathfinding and fog of war!

  • @SkellingtonWheel
    @SkellingtonWheel Před 2 lety +2

    So from what I see, this creates multiple hexagon meshes and then aligns them side-by-side so that neighbouring vertices overlap. Is there a way to merge the overlapping vertices in a way that retains the triangle faces, so that something like a perlin noise algorithm could generate some cool terrain?

  • @falricthesleeping9717
    @falricthesleeping9717 Před 2 lety

    This Was a great video, albeit, I found myself not quite understanding what's going on where you used sin and cosin, but perhaps that's my job to actually study the link that you provided
    I was Looking for procedural generation and this video was helpful to what things I must do, but I will probably not use a hex grid in the foreseeable future
    awesome video thanks mate

  • @iurieysi9103
    @iurieysi9103 Před 2 lety +1

    5:38 if you want to convert to radians Mathf has a Deg2Rad constant which is equal to Mathf.PI/180f

    • @j.j.maverick9252
      @j.j.maverick9252 Před 2 lety +1

      I thought the same thing but realised it’s always good to know the derivation of those constants too… some game engines don’t have them, and not all programmers use them.

    • @iurieysi9103
      @iurieysi9103 Před 2 lety

      @@j.j.maverick9252 I agree

  • @flashpaperdotru
    @flashpaperdotru Před 2 lety

    This is a very cool video and it will help me a lot in my engine. Thanks!

  • @lesliejohnrichardson
    @lesliejohnrichardson Před 2 lety

    Damn this was definitely an amazing video that inspired me to choose hexagons as the general theme for my game :D

  • @DaneC020
    @DaneC020 Před 2 lety +1

    Looking forward to the pathfinding and fog of war episodes!

  • @simplegamedev4342
    @simplegamedev4342 Před 2 lety

    Great video, can't wait for the next one :)

  • @alexandrecolautoneto7374
    @alexandrecolautoneto7374 Před 7 měsíci

    Tried to make a square board, when I looked all my squares got 6 sides, Hexagons are truly the bestagon.

  • @Mouton_redstone
    @Mouton_redstone Před 2 lety

    I am very excited for the pathfinding

  • @gorgeousorc
    @gorgeousorc Před 5 měsíci

    Great tutorial, straightforward! Thanks.
    One thing I noticed was forgetting to disable OnEnable drawing of mesh after implementing the HexGridLayout. Which was resulting in the grid creating 2 versions of itself. A sneaky catch that was leading to performance issues.
    I have a question, maybe you have addressed already, but how would you approach giving each hex a collider to be raycasted/interacted with? I tried creating a MeshCollider based on the sharedMesh of the mesh we create but to no avail.

  • @pifopifo1000
    @pifopifo1000 Před 2 lety

    As some once famous youtuber said, Hexagons are the bestagons.

  • @TemProduction
    @TemProduction Před 2 lety +2

    From which games did you use the clips in this video?
    Also can you draw hexagon shaped grids, so all the hexagon tiles in a hexagon shape
    Thank You

  • @rohan_mayya
    @rohan_mayya Před 2 lety +6

    This is still somewhat incomplete.
    - What about retrieving a vertex or edge on demand?
    - What about hex representation? Cube/axial/offset? What would you suggest is the easiest way to retrieve a hex (say, by a map) given your implementation?

    • @rohan_mayya
      @rohan_mayya Před 2 lety

      Good video by the way, just feel like it can be taken a notch above with a part 2

  • @michaelsander2878
    @michaelsander2878 Před 2 lety +1

    That was a sick hexagons are the bestagons reference. +1

  • @lonkerr5588
    @lonkerr5588 Před 2 lety

    Thank you so much!

  • @bachhoang9004
    @bachhoang9004 Před 2 lety

    awesome as always

  • @magq1246
    @magq1246 Před rokem

    great vid, great explanations, love it +1 follower

  • @ObsessiveGames
    @ObsessiveGames Před 2 lety

    Great tutorial thanks

  • @ggshout3019
    @ggshout3019 Před rokem

    Made it all works except the last part with the grid, for that I slapped a prompt in ChatGPT and works now. It was confusing at times, but it's doable.

  • @rutchjohnson
    @rutchjohnson Před 2 lety

    Yessss! I love this tutorial!!

  • @Developesque
    @Developesque Před 2 lety

    Thanks for this guide, it helped me out a lot.
    Anyone have tips for laying this grid on top of a plane programmatically?
    I am eventually trying to project the grid overtop of terrain.
    Step at a time.

  • @DS-rd8ud
    @DS-rd8ud Před 2 lety

    Cool video. The background music is a bit distracting, though. Keep it up!

  • @wannachill4982
    @wannachill4982 Před 2 lety +4

    I got a problem. For some reason my OnValidate is not working properly. I can change innerSize or outerSize but while changing it leaves like trace of tiles and they are not removing (
    Also in LayoutGrid() i cant write tile.SetParent(transform, true); because .transform is missing - so i think may be it can cause my problem?

    • @jamesmamaliga4824
      @jamesmamaliga4824 Před rokem

      I'm having the same issue, did you manage to fix it?

    • @wannachill4982
      @wannachill4982 Před rokem

      @@jamesmamaliga4824 No

    • @MrYTThor
      @MrYTThor Před rokem +8

      Did you try it with a newer version? Try changing it to:
      tile.transform.SetParent(transform, true);
      Maybe it helps.

    • @AliveNotDeadmund
      @AliveNotDeadmund Před rokem +1

      @@MrYTThor Thank you!

    • @Rhanati
      @Rhanati Před 9 měsíci

      The created tiles are not deleted. To achieve this, you can add a ClearGrid() to the onValidate():
      Add a List of the created tiles:
      private List tiles = new List();
      Add all created tiles in the LayoutGrid to this List:
      tiles.Add(tile);
      Create a ClearGrid function:
      private void ClearGrid()
      {
      foreach (GameObject tile in tiles)
      {
      Destroy(tile);
      }
      tiles.Clear();
      }
      Call the ClearGrid(); before LayoutGrid(); in your OnValidate().

  • @Lukazkool
    @Lukazkool Před rokem +2

    When I am setting up the DrawFaces() Method, it is saying that innerSize, outerSize, height, and height don't exist in the current context. I already tried swapping them with innerRad, outerRad, heightA, and heightB, but it still didn't work. Does anyone know how to fix this?

  • @Kwevino
    @Kwevino Před rokem +1

    How do you use the script? What do you do after you've written it?

  • @jasher1608
    @jasher1608 Před rokem +1

    Hello, does anyone know how I could outline the grid so that I could see the borders of the individual hexes? Thank you

  • @Lastered
    @Lastered Před 2 lety +2

    Does anyone know what game that is at 0:23 ?
    I've been looking to play that game!
    Edit: for anyone wondering the game is called Opus Magnum by Zachtronics

  • @zweitkolben7687
    @zweitkolben7687 Před 11 měsíci +2

    Okay so I did everything just as in the video up until the point where the Hexagon should render but nothing happens. Since it wasnt stated in the video, I attached the Script to an Empty Gameobject so it would run but still nothing happens. Can anyone explain what type of Gameobject to attach the Script to or what I did wrong?

    • @JohannesOnYouTube
      @JohannesOnYouTube Před 5 měsíci

      If you start out with an empty project, do the following: 1) add an empty gameobject 2) attach the HexRenderer.cs to it 3) position the camera so it looks at the object 4) press the Play button to run the scene
      Also, check the other comments to sort out some issues since there are changes done to the code that are not highlighted in the video.

  • @thipoktham5164
    @thipoktham5164 Před 2 lety

    Hello, this video is awesome!

  • @Galaxhjalt
    @Galaxhjalt Před 4 měsíci

    i am getting a CS0103 error for height, innersize and outersize for the Drawfaces method at the end.
    i cant see any misstakes that i have made in my code, any help?

  • @jthale7381
    @jthale7381 Před 10 měsíci

    For anyone wondering why it's not working on newer versions of Unity you need to comment out the OnValidate method and replace the OnEnable method with Update. This will make sure it draws every frame like in the video, just won't work in the editor.

  • @masonmason22
    @masonmason22 Před 2 lety

    Very nice.

  • @RG-ef8vm
    @RG-ef8vm Před rokem

    Nice video, I was able to follow along just fine, and complete the project. Question: When I create the grid initially, it takes ~250ms. However, when it is recreated using OnValidate, it takes over 5 seconds. I then tested by just calling Invoke("LayoutGrid", 10f) in Start(), and changing the inner size before the 10s expired, and it again took only ~250ms. Why does it take ~20x longer to execute when called in OnValidate?

  • @Tin_Protopixel
    @Tin_Protopixel Před 2 lety +2

    When I create m_mesh=new Mesh() later in the CombineFaces() I get NullReferenceException: Object reference not set to an instance of an object . After debugging tunes out that ,_mesh is still null. Been looking at this for a while now and cant figure out why.

    • @SkellingtonWheel
      @SkellingtonWheel Před 2 lety +1

      I had the same issue, another commenter wrote the solution. In "OnValidate()" add "&& mesh != null" in the if statement, after Application.isPlaying

    • @Tin_Protopixel
      @Tin_Protopixel Před 2 lety

      @@SkellingtonWheel cant confirm myself(not using the project anymore), but if anyone reading and trying this, please confirm if true

    • @leventeberes3829
      @leventeberes3829 Před 2 lety

      @@Tin_Protopixel I had the same problem, and using the check made it go away.

  • @MatthiasTTV
    @MatthiasTTV Před rokem +1

    You shouldn't just arrange the hexagons next to each other; you should check if there is a neighboring hex and not redraw those edges. You'll save a huge number of tris and verts.

  • @tkg__
    @tkg__ Před 2 lety +3

    Hexagon is the bestagon, obviously.

  • @bradleysmith9924
    @bradleysmith9924 Před 2 lety

    Any advice for presenting/wrapping the grid around a sphere?

  • @DoctorMGL
    @DoctorMGL Před 2 lety +2

    i wish there was good programming tutorials like this for unreal engine :/
    and c++ feels more complex anyway ..

  • @radicaldaddy8149
    @radicaldaddy8149 Před 9 měsíci

    Hi, I finished writing the code but how do i make it so it would automaically run after I start my program?

  • @KaryoSentiko
    @KaryoSentiko Před měsícem

    I am certain I have followed this to the letter, but I am getting a null reference exception error. Anybody have any idea why?

  • @SpankytheEvilMo
    @SpankytheEvilMo Před 2 lety +2

    I copied your code on screen exactly and it didn't output anything but errors. Is it because you switched terms without correcting the edit? For example, the private void DrawFaces had very similar code to the private void DrawMesh.

    • @junjiepeng
      @junjiepeng Před rokem +1

      I have the same problem that there is no output but two errors.I cant find any difference between video and my codes.

    • @AliveNotDeadmund
      @AliveNotDeadmund Před rokem +1

      Glad I'm not the only one. I've tried the fixes put forward by other commenters and none of them work. Would be nice to see the script in full at the end of writing. :/

    • @Liamneedham29
      @Liamneedham29 Před rokem +2

      @@junjiepeng Two Errors. Perhaps we have the same ones. HexRenderer does not contain a definition for SetMaterial, and same thing for GameObject ... Set Parent. If I find solution, I will post it here. Just starting to get back into code after years and years haitus, and I was never that proficient, so I expect to run into a lot of errors.
      Copying the code from the video is really difficult, it changes slide to slide as he fixes errors between shots. This is not to mention that I have no doubt mistyped something, it makes following the tutorials and actually getting something working to play around with very difficult, but I just can't learn on theory only. Would be good to see the final clips of the script.

    • @Liamneedham29
      @Liamneedham29 Před rokem +1

      Okay I've found the problem. At some point, UnityEngine stopped allowing a bunch of the components of GameObject to be referenced. Don't know how long ago this change happened, can't find any documentation on the update itself. SetParent is now part of Transform, so the correct line here is
      tile.transform.SetParent(transform, true);
      The SetMaterial on the other hand doesn't exist at all, only as part of a CanvasRenderer. This line just appears to be completely wrong. In this part of the code we are creating GameObjects of type HexRenderer, referencing the variables at the top of the HexRenderer script, and assigning to them the variables in this script. So the material should be the same pattern as all the other variables we used.
      hexRenderer.material = material;
      I think, I could be wrong, but the errors go away with these changes. Hope this helps. Annoying that the video is either already out of date after a year, or just riddled with mistakes. Clearly a lot of work has been put into making the video, but its a big barrier to learning that videos need to be basically perfect and released a day ago to be even functional.
      Even after fixing these errors, I still have a lot of tweaking to do to even get Hexagons appearing, which I see is a problem many others were having.

    • @divac7777
      @divac7777 Před rokem +1

      @@Liamneedham29 Got those same 2 errors

  • @Mat-r5n
    @Mat-r5n Před měsícem

    My console is returning the error code:
    Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
    UnityEngine.Mesh:set_uv (UnityEngine.Vector2[])
    But it seems to be generating the hexagon correctly. Still, it's a bit annoying... how do I fix this? It's also returning a:
    NullReferenceException: Object reference not set to an instance of an object
    At first, but it disappears if I remove the OnValidate() function.
    Edit: I ran into another problem... Whenever I try to adjust it on the HexGridLayout script, it always instantiate new cells instead of adjusting the existing cells.

  • @ragerungames
    @ragerungames Před 2 lety

    Awesome!!

  • @BurzowySzczurek
    @BurzowySzczurek Před 2 lety

    0:01 What kraków does there? I live in it. (Actually on a border)

  • @paulrumyancev
    @paulrumyancev Před 2 lety +2

    Why not to use Unity's Tilemap package?
    It has 2D hexagonal tiles implementation out of the box. It isn't 3D but for needs of prototyping, as stated in the video, it works perfectly

  • @DavidVille
    @DavidVille Před 2 lety +2

    CGP Grey

  • @KICKinYaFACE
    @KICKinYaFACE Před 2 lety +1

    How are you managing the children of the HexLayout GameObject? This part isn't shown in the video ... the way it is presented is calling LayoutGrid() inside OnValidate() and this causes a re-creation of the entire HexGrid on top of the existing one - on every single tick of OnValidate. As workaround, I added a short cleanup before calling LayoutGrid to wipe away all children of the HexGrid before creating a new one, but this doesn't seem to be the most efficient way of doing things.

  • @D-Dev
    @D-Dev Před 2 lety

    It’s looks really cool but how about with performance in this this solution. Can we just save somehow our procedurally generated hex as prefab and not calculated it each time when we want to display it?

  • @xanmichaels
    @xanmichaels Před rokem +1

    I can't seem to show my hex in the scene . The only way I can see my hex is by hitting the play button. Is there is a download link for the code maybe I miss something

    • @xanmichaels
      @xanmichaels Před rokem +1

      i have the content downloaded from patron it just made it worst. i just want this thing to show up in scene lol.

  • @Raccoon0710
    @Raccoon0710 Před rokem

    I have an issue, hexagon is not rendered if it’s center is outside of my camera view 😢

  • @SaiponathGames
    @SaiponathGames Před 2 lety

    Nice!

  • @r.rodriguez4991
    @r.rodriguez4991 Před rokem

    What is the game at 0:08? The art style is awesome.

  • @twentyhands
    @twentyhands Před 2 lety

    Me, just starting to learn game dev: "mhm, I know some of these words."

  • @tristanbluhm
    @tristanbluhm Před 2 lety +1

    What is the name of the game at 0:23, I can never remember the name and I've been wanting to play it

  • @Kashev101
    @Kashev101 Před 7 měsíci

    the hexRenderer.SetMaterial(material) is giving an error in unity saying the HexRenderer script does not contain a definition for SetMaterial, Anybody know the fix around that?

  • @GodGuy8
    @GodGuy8 Před rokem

    you need to paste the code in the description or github bc for me a lot of stuff is underlined in red and im not sure why. its cool that this stuff is possible but seems a little out of reach for me rn without more help. thanks though

  • @vinhnghiang1273
    @vinhnghiang1273 Před 2 lety +1

    What is the name of the game at 0:47???

  • @naramoro
    @naramoro Před 2 lety

    What's the game at 0:08-0:10? Looks awesome

  • @RandomProduct
    @RandomProduct Před 2 lety

    0:28 what game is this? It looks adorable.

  • @RickoDeSea
    @RickoDeSea Před 2 lety

    What are the names of those games u showed as examples ?

  • @musey86
    @musey86 Před rokem

    Think this needs an update, tried doing this is Unity 2021.3.19f1 and while I can make a grid, I get a tonne of warnings thrown out about "Send message cannot be called during Awake, CheckConsistency, or OnValidate" - If I comment out the 'On validate' sections the grid won't generate, but if I leave them in, when I update the grid size it leaves the hexes that should disappear causing a mess of gameobjects.
    Also, even though the code is carbon-copy of what's show, when I invert into the 'IsFlatTopped', the hexes will move but they're not aligned properly.

    • @GrigTea
      @GrigTea Před rokem

      I have the same problem. Were you able to fix it?