Procedurally Generating A Hexagon Grid in Unity

  Рет қаралды 115,879

Game Dev Guide

Game Dev Guide

Күн бұрын

Hexagons are common in a lot of strategy games, so today let's look at how we can create them from scratch in Unity.
Further Reading - www.redblobgames.com/grids/he...
--------------------------------------------------------------------------------
Want to support the channel?
▶️ Help fund new episodes and get free project downloads by joining the Patreon - / gamedevguide
💡 Get One-Month Free of Skillshare Premium - skl.sh/MKR826
Use these links to grab some cool assets from the asset store:
Get the Must Have Assets! - assetstore.unity.com/top-asse...
Free Unity Assets! - assetstore.unity.com/top-asse...
New on the Asset Store! - assetstore.unity.com/top-asse...
Top Paid Asset Store Packages - assetstore.unity.com/top-asse...
Asset Store Partners - assetstore.unity.com/lists/as...
--------------------------------------------------------------------------------
Socials and Other Stuff:
• Subscribe - kzfaq.info?...
• Join the Discord - / discord
• Twitter - / gamedevguideyt
• Facebook - / gamedevguideyt
• Instagram - / gamedevguideyt

Пікірлер: 218
@NachitenRemix
@NachitenRemix 2 жыл бұрын
Hexagon is the bestagon.
@yahlunna9799
@yahlunna9799 2 жыл бұрын
In this house we follow the church of Grey
@pepedelospalos9339
@pepedelospalos9339 2 жыл бұрын
Amen dude
@dark5358
@dark5358 2 жыл бұрын
Porygon > any polygon Otherwise yes
@sunflower4031
@sunflower4031 2 жыл бұрын
All praise our lord hexagon.
@yuriwaki2582
@yuriwaki2582 2 жыл бұрын
scrolled too far to fin this xD
@stonefreak5763
@stonefreak5763 2 жыл бұрын
Hint: If u want to stay in 2D, then the Grid Component in Unity has an option for exactly that.
@AGreatTsunami
@AGreatTsunami 2 жыл бұрын
And one can always extrapolate a tilemap into 3D objects~
@3nertia
@3nertia 2 жыл бұрын
@@AGreatTsunami Wait, what? Would you happen to know of a video or article detailing what you mentioned?
@NominativoUnivoco
@NominativoUnivoco 2 жыл бұрын
However, those hexagons are not accurate
@vinhnghiang1273
@vinhnghiang1273 Жыл бұрын
what is the game at 0:47 ?
@mcfnord
@mcfnord Жыл бұрын
@@NominativoUnivoco Why aren't the Grid Component hexes inaccurate? I have a game that needs hex grid
@simoncodrington
@simoncodrington 2 жыл бұрын
Another great video mate cheers. Can't wait to see what you come up with next!
@bakerfx4968
@bakerfx4968 2 жыл бұрын
My face lit up when I saw you had a new video. It was amazing as always! Thanks dude
@mrlucky974
@mrlucky974 2 жыл бұрын
YES ! Your videos are so great, and this one did not disappoint. Hexagons are the bestagons...
@andrewwilson9052
@andrewwilson9052 2 жыл бұрын
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
@3nertia
@3nertia 2 жыл бұрын
Thank you so much! I searched and searched for this exact thing to no avail!
@blainewordly9134
@blainewordly9134 2 жыл бұрын
great tutorial can't wait for the next one on hexagonal grids!
@weks
@weks 2 жыл бұрын
Amazing stuff as always! Thanks for the content!
@AliveNotDeadmund
@AliveNotDeadmund Жыл бұрын
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... Жыл бұрын
Hi, can you check my code, i thing ive done big wrong :8 nothing works
@rickbeniers667
@rickbeniers667 Жыл бұрын
thanks for the comment I had missed him rewritting that part haha
@nj5374
@nj5374 2 жыл бұрын
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!!
@nightfox4013
@nightfox4013 2 жыл бұрын
This man deserves more attention, he’s so helpful.
@simplegamedev4342
@simplegamedev4342 2 жыл бұрын
Great video, can't wait for the next one :)
@Ferenc-Racz
@Ferenc-Racz 2 жыл бұрын
Thank you for your knowledge sharing. Subscribed and liked offcorse. :)
@Rhanati
@Rhanati 8 ай бұрын
This is an awesome video, thank you for the explanation!
@Island54Games
@Island54Games 2 жыл бұрын
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 2 жыл бұрын
Is It Possible You Can Show How To Use Axial instead of Offset coordinate system?
@flashpaperdotru
@flashpaperdotru 2 жыл бұрын
This is a very cool video and it will help me a lot in my engine. Thanks!
@cryzz0n
@cryzz0n 2 жыл бұрын
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
@DevOverdrive
@DevOverdrive 2 жыл бұрын
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.
@TimurKOI
@TimurKOI Жыл бұрын
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!
@Dranzer10HD
@Dranzer10HD 2 жыл бұрын
I've found my new favourite gamedev channel! :D
2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@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 Жыл бұрын
what is the game at 0:47 ?
@brainwavestobinary
@brainwavestobinary Жыл бұрын
@@vinhnghiang1273 That game is called, "Before we Leave".
@DmytroMomotov
@DmytroMomotov 2 жыл бұрын
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
@stephenkirby6788
@stephenkirby6788 2 жыл бұрын
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!
@lesliejohnrichardson
@lesliejohnrichardson 2 жыл бұрын
Damn this was definitely an amazing video that inspired me to choose hexagons as the general theme for my game :D
@lacata2570
@lacata2570 2 жыл бұрын
"Hexagons are the bestagons" felt like a CGP Grey easter egg
@mobilelast1715
@mobilelast1715 2 жыл бұрын
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.
@ekzac
@ekzac Жыл бұрын
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. :)
@bachhoang9004
@bachhoang9004 2 жыл бұрын
awesome as always
@falricthesleeping9717
@falricthesleeping9717 2 жыл бұрын
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
@rutchjohnson
@rutchjohnson 2 жыл бұрын
Yessss! I love this tutorial!!
@j.j.maverick9252
@j.j.maverick9252 2 жыл бұрын
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
@GameDevGuide
@GameDevGuide 2 жыл бұрын
Watchout for part 2 😉
@j.j.maverick9252
@j.j.maverick9252 2 жыл бұрын
@@GameDevGuide subscribed and notified!
@Nanukimo
@Nanukimo 2 жыл бұрын
@@GameDevGuide Whens Part 2??
@vinhnghiang1273
@vinhnghiang1273 Жыл бұрын
what is the game at 0:47 ?
@magq1246
@magq1246 Жыл бұрын
great vid, great explanations, love it +1 follower
@ObsessiveGames
@ObsessiveGames 2 жыл бұрын
Great tutorial thanks
@jeshuanavarrogarcia
@jeshuanavarrogarcia Жыл бұрын
Thanks, and waiting for the next video for thepathfinding and fog of war!
@Jonny01Boy
@Jonny01Boy 2 жыл бұрын
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 Жыл бұрын
I'm having trouble setting up the innersize, outersize, and height. Can you help?
@WildPork
@WildPork Жыл бұрын
@@HaoaHaNa8513 [SerializeField] private Material material; [SerializeField] private float innerSize; [SerializeField] private float height; [SerializeField] private float outersize; then set them in the inspector
@HereBeCush
@HereBeCush Жыл бұрын
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 Жыл бұрын
what is the game at 0:47 ?
@GregX999
@GregX999 Жыл бұрын
You can also just use "mesh.RecalculateBounds()" right after "mesh.RecalculateNormals()" in the "CombineFaces()" method.
@HereBeCush
@HereBeCush Жыл бұрын
@@GregX999 Awesome, didn't know this - thanks!
@rutchjohnson
@rutchjohnson 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@SpankytheEvilMo I've only completed generating the hex. The code in the video works. I haven't started coding the grid yet.
@SpankytheEvilMo
@SpankytheEvilMo 2 жыл бұрын
@@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 2 жыл бұрын
@@SpankytheEvilMo I’m not using a custom editor.
@dislexei
@dislexei Жыл бұрын
Thank you! Been debugging that one for the last couple of hours :)
@blizzzard900
@blizzzard900 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?
@akmaludddin9281
@akmaludddin9281 3 ай бұрын
i love how you show the code. i sub immediately! i hope all of you have fun and great days!
@TemProduction
@TemProduction 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
@lonkerr5588
@lonkerr5588 2 жыл бұрын
Thank you so much!
@Developesque
@Developesque 2 жыл бұрын
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.
@BlueHat1
@BlueHat1 Жыл бұрын
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.
@boiimcfacto2364
@boiimcfacto2364 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.
@thipoktham5164
@thipoktham5164 2 жыл бұрын
Hello, this video is awesome!
@bradleysmith9924
@bradleysmith9924 2 жыл бұрын
Any advice for presenting/wrapping the grid around a sphere?
@ragerungames
@ragerungames 2 жыл бұрын
Awesome!!
@Mouton_redstone
@Mouton_redstone 2 жыл бұрын
I am very excited for the pathfinding
@mementomori7160
@mementomori7160 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
@jasher1608
@jasher1608 Жыл бұрын
Hello, does anyone know how I could outline the grid so that I could see the borders of the individual hexes? Thank you
@masonmason22
@masonmason22 2 жыл бұрын
Very nice.
@DaneC020
@DaneC020 2 жыл бұрын
Looking forward to the pathfinding and fog of war episodes!
@Kwevino
@Kwevino Жыл бұрын
How do you use the script? What do you do after you've written it?
@gorgeousorc
@gorgeousorc 4 ай бұрын
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.
@SaiponathGames
@SaiponathGames 2 жыл бұрын
Nice!
@RG-ef8vm
@RG-ef8vm 11 ай бұрын
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?
@DS-rd8ud
@DS-rd8ud 2 жыл бұрын
Cool video. The background music is a bit distracting, though. Keep it up!
@radicaldaddy8149
@radicaldaddy8149 8 ай бұрын
Hi, I finished writing the code but how do i make it so it would automaically run after I start my program?
@dptgames2254
@dptgames2254 Жыл бұрын
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 Жыл бұрын
You probably need to create a new GameObject (named "Hex") and add component > script (HexRenderer) to get to the next point in the video.
@D-Dev
@D-Dev 2 жыл бұрын
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?
@iurieysi9103
@iurieysi9103 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@j.j.maverick9252 I agree
@BurzowySzczurek
@BurzowySzczurek 2 жыл бұрын
0:01 What kraków does there? I live in it. (Actually on a border)
@jackpaice
@jackpaice Жыл бұрын
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.
@meowsqueak
@meowsqueak 2 жыл бұрын
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_ Жыл бұрын
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 Жыл бұрын
@@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.
@ggshout3019
@ggshout3019 Жыл бұрын
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.
@Tin_Protopixel
@Tin_Protopixel 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.
@blizzzard900
@blizzzard900 2 жыл бұрын
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 2 жыл бұрын
@@blizzzard900 cant confirm myself(not using the project anymore), but if anyone reading and trying this, please confirm if true
@leventeberes3829
@leventeberes3829 Жыл бұрын
@@Tin_Protopixel I had the same problem, and using the check made it go away.
@Raccoon0710
@Raccoon0710 Жыл бұрын
I have an issue, hexagon is not rendered if it’s center is outside of my camera view 😢
@RickoDeSea
@RickoDeSea 2 жыл бұрын
What are the names of those games u showed as examples ?
@Lukazkool
@Lukazkool Жыл бұрын
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?
@androsynth976
@androsynth976 Жыл бұрын
6:24
@zweitkolben7687
@zweitkolben7687 10 ай бұрын
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 4 ай бұрын
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.
@Galaxhjalt
@Galaxhjalt 3 ай бұрын
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?
@Tasarran
@Tasarran 2 жыл бұрын
Instant like for "Hexagons are the bestagons!"
@wannachill4982
@wannachill4982 2 жыл бұрын
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 Жыл бұрын
I'm having the same issue, did you manage to fix it?
@wannachill4982
@wannachill4982 Жыл бұрын
@@jamesmamaliga4824 No
@MrYTThor
@MrYTThor Жыл бұрын
Did you try it with a newer version? Try changing it to: tile.transform.SetParent(transform, true); Maybe it helps.
@AliveNotDeadmund
@AliveNotDeadmund Жыл бұрын
@@MrYTThor Thank you!
@Rhanati
@Rhanati 8 ай бұрын
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().
@PhaygeWoW
@PhaygeWoW 8 ай бұрын
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?
@musey86
@musey86 Жыл бұрын
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 Жыл бұрын
I have the same problem. Were you able to fix it?
@xanmichaels
@xanmichaels Жыл бұрын
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 Жыл бұрын
i have the content downloaded from patron it just made it worst. i just want this thing to show up in scene lol.
@alexandrecolautoneto7374
@alexandrecolautoneto7374 6 ай бұрын
Tried to make a square board, when I looked all my squares got 6 sides, Hexagons are truly the bestagon.
@r.rodriguez4991
@r.rodriguez4991 Жыл бұрын
What is the game at 0:08? The art style is awesome.
@pifopifo1000
@pifopifo1000 2 жыл бұрын
As some once famous youtuber said, Hexagons are the bestagons.
@MilanObrtlik
@MilanObrtlik 2 жыл бұрын
Youre epic. Just epic.
@SpankytheEvilMo
@SpankytheEvilMo 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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
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 Жыл бұрын
@@Liamneedham29 Got those same 2 errors
@Lastered
@Lastered 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
@7yearsago440
@7yearsago440 2 жыл бұрын
Thanks
@UHILLE
@UHILLE 2 жыл бұрын
ı try to write same code to develop my skills but in the point of we create "m_faces.Add(CreateFace(innerSize,outerSize,height/2f,height/2f,point));" this code ı have an error which is "the name innerSize does not exist in the current context" but we use that name to refer to "private Face CreateFace(float innerRad, float outerRad, float heightA, float heightB, int point, bool reverse = false)" but it doesnt work can anyone help me about this error
@UHILLE
@UHILLE 2 жыл бұрын
o after that you showed the creation of public float innerSize codes okey ı am fine now :D but how can you do that unity drawing things ı couldnt see that
@Kashev101
@Kashev101 6 ай бұрын
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?
@tristanbluhm
@tristanbluhm 2 жыл бұрын
What is the name of the game at 0:23, I can never remember the name and I've been wanting to play it
@lucasd.3369
@lucasd.3369 Жыл бұрын
OPUS MAGNUM
@Mat-r5n
@Mat-r5n 18 күн бұрын
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.
@naramoro
@naramoro 2 жыл бұрын
What's the game at 0:08-0:10? Looks awesome
@GodGuy8
@GodGuy8 Жыл бұрын
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
@eemelivaisanen6249
@eemelivaisanen6249 2 жыл бұрын
Why doesn't the hex gameobject appear in my hierarchy after 4:12 ? I've checked spelling etc a few times already and everything is the same as in the video. There are no errors
@dptgames2254
@dptgames2254 Жыл бұрын
Iv'e got this problem, did you find a solution?
@nathanwakefield1081
@nathanwakefield1081 Жыл бұрын
​@@dptgames2254 I had this problem, I think I needed to create an empty GameObject to attach the script to
@jthale7381
@jthale7381 9 ай бұрын
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.
@Raven-su7bw
@Raven-su7bw 2 жыл бұрын
0:27 what game is it?
@vinhnghiang1273
@vinhnghiang1273 2 жыл бұрын
What is the name of the game at 0:47???
@KaryoSentiko
@KaryoSentiko 13 күн бұрын
I am certain I have followed this to the letter, but I am getting a null reference exception error. Anybody have any idea why?
@KindredNetwork
@KindredNetwork 2 жыл бұрын
I wonder, since you're creating groups of faces and then just sticking the returned values in an array, are you not just duplicating some vertices? For a single solid hex that has a height, you should only have 12 vertices per hex. This seems like you'd have 36. This would obviously double with the hollow inner version. I didn't see any correcting code on the vertices array merge.
@GameDevGuide
@GameDevGuide 2 жыл бұрын
So this decision is mostly due to the way UV Mapping works in Unity. If you want clean UVs easily you need to define unique vertices. If you don't care as much about UVs, sharing vertices is a lot more optimal.
@tkg__
@tkg__ 2 жыл бұрын
You can actually go as low as 6 vertices and 4 triangles per hex.
@DoctorMGL
@DoctorMGL 2 жыл бұрын
i wish there was good programming tutorials like this for unreal engine :/ and c++ feels more complex anyway ..
@joshdoucette6802
@joshdoucette6802 2 жыл бұрын
Noice!!!
@Belu123mm
@Belu123mm 2 жыл бұрын
The music is too loud :c Great video
@michaelsander2878
@michaelsander2878 2 жыл бұрын
That was a sick hexagons are the bestagons reference. +1
@MatthiasTTV
@MatthiasTTV Жыл бұрын
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.
Unity Tilemaps - Hex, rectangle, isometric + rule tiles
18:38
Generating A Hex Map With Fog Of War in Unity
20:27
Game Dev Guide
Рет қаралды 50 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 28 МЛН
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 20 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 418 М.
Building a Camera Controller for a Strategy Game
17:48
Game Dev Guide
Рет қаралды 192 М.
Why Animation Curves In Unity Are So Useful
7:39
Game Dev Guide
Рет қаралды 76 М.
How To Build Roads Procedurally In Unity with the Splines Package
17:51
11 Things You (Probably) Didn't Know You Could Do In Unity
13:49
Game Dev Guide
Рет қаралды 150 М.
Unlocking The Power Of Unity's Scriptable Render Pipeline
21:05
Game Dev Guide
Рет қаралды 197 М.
The 6 Design Patterns game devs need?
24:20
Jason Weimann
Рет қаралды 364 М.
What's a hex grid? How to make? (Unreal Engine)
12:23
AziApps
Рет қаралды 419
How To Get A Better Grid Layout in Unity
12:04
Game Dev Guide
Рет қаралды 205 М.