How to make a Hex Grid System Unity Tutorial! (Like Civilization, Opus Magnum, Gloomhaven)
Vložit
- čas přidán 13. 09. 2024
- ✅ Get the Project files and Utilities at unitycodemonke...
🌍 Get my Complete Courses! ✅ unitycodemonke...
👍 Learn to make awesome games step-by-step from start to finish.
👇 Click on Show More
🎮 Get my Steam Games unitycodemonke...
🔴 RELATED VIDEOS 🔴
How to Test if a POINT is inside a HEX! (No Raycasts, Just Simple Math) • How to Test if a POINT...
Hex Pathfinding Unity Tutorial! (Hex Grid System) • Unity Pathfinding on a...
Awesome Hex Grid System Unity Tutorial! (Like Civilization, Opus Magnum, Gloomhaven) • How to make a Hex Grid...
Grid System in Unity (How to make it and where to use it) • Grid System in Unity (...
Take your Skills to the NEXT LEVEL by making a Turn-Based Strategy game! (Unity Complete Course) • Take your Skills to th...
How to get Mouse Position in 3D and 2D! • How to get Mouse Posit...
Awesome Grid Building System! (City Builder, RTS, Factorio, Survival) • Awesome Grid Building ...
I Made a Factory Game in 20 HOURS! • I Made a Factory Game ...
Unity Tip: Magic Numbers! • Unity Tip: Magic Numbe...
Custom Tilemap in Unity with Saving and Loading (Level Editor) • Custom Tilemap in Unit...
How to make a Mesh in Unity (Dynamic, Vertices, UVs, Triangles) • How to make a Mesh in ...
A* Pathfinding in Unity • A* Pathfinding in Unity
💬 Let's convert our Square Grid System into a Hex Grid System. This involves changing the shape of each Grid Position and also the position itself since odd rows have an offset compared to even rows.
The only complex part of this system is testing which Hex is the selected one, doing that involves grabbing a rough Hex Grid Position then testing the distance against itself and all it's neighbors.
📝 Some Links are Affiliate links which means it costs the same to you and I get a nice commission.
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!
✅ store.steampow...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🎮 Grab the Game Bundle at unitycodemonke...
📝 Get the Code Monkey Utilities at unitycodemonke...
#unitytutorial #unity3d #gamedev
--------------------------------------------------------------------
Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.
I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Other great Unity channels:
Unity - / unity3d
Brackeys - / brackeys
Dani - / @danidev
Jabrils - / @jabrils
BlackthornProd - / @blackthornprod
Sykoo - / sykootv
Jason Weimann - / @unity3dcollege
Jonas Tyroller - / @jonastyroller
--------------------------------------------------------------------
- Website: unitycodemonke...
- Twitter: / unitycodemonkey
- Steam: store.steampow...
✅ Get the Project files and Utilities at unitycodemonkey.com/video.php?v=0nXmuJuWS8I
🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
🔴 RELATED VIDEOS 🔴
How to Test if a POINT is inside a HEX! (No Raycasts, Just Simple Math) czcams.com/video/dqframYHfws/video.html
Grid System in Unity (How to make it and where to use it) czcams.com/play/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722.html
Take your Skills to the NEXT LEVEL by making a Turn-Based Strategy game! (Unity Complete Course) czcams.com/video/QDr_pjzedv0/video.html
How to get Mouse Position in 3D and 2D! czcams.com/video/0jTPKz3ga4w/video.html
Awesome Grid Building System! (City Builder, RTS, Factorio, Survival) czcams.com/video/dulosHPl82A/video.html
I Made a Factory Game in 20 HOURS! czcams.com/video/88cIVR4KI_Q/video.html
Unity Tip: Magic Numbers! czcams.com/users/shortsCQ5xHgRZGQo
Custom Tilemap in Unity with Saving and Loading (Level Editor) czcams.com/video/gD5EQyt7VPk/video.html
How to make a Mesh in Unity (Dynamic, Vertices, UVs, Triangles) czcams.com/video/11c9rWRotJ8/video.html
A* Pathfinding in Unity czcams.com/video/alU04hvz6L4/video.html
In the original article you were researching during the livestream, I recall they had a radial method for hex grids, rather than a rectangular one like you have here, where the grid counts cells along each of the axes of the hex (so like NE, SW, etc.). This allows a grid to spawn from the center-out, evenly in all directions while filling in gaps. Would be interested to see you try to make that one and to do it with perfect regular hexes with 120-degree angles.
Yup that method ends up with a slightly more pointy hex since the width does not equal the height like I used here. It might simplify some things but might also make some others more complex since in that case the height is sqrt(3) * width which is a very strange number.
There is also another way of positioning all the grid positions by "rotating" the grid 60º so it's on an angle rather than being more rectangular shape like I made here.
There's definitely a lot more that can be explored in this area!
An exceptional well made tutorial, thank you!
Everything what you need: Interesting topic. Starting with explaining the problems you'll face and how to solve them in theory. Then solving it step by step while coding, incl. some remarks about proper coding. Outlook on further posible improvements. Everything (as usual) nicely demonstrated and with helpful links to your related videos.
Makes me want to start your complete game course. I picked it up, but had no time so far.
I'm building my game (you may remember it from looking at it in one of the live streams) based on Catlike Coding's hex map tutorial and have actually created a bunch of Dev Logs on my channel showing how I expand on the original tutorial - I actually saw some of my videos when you scrolled through the CZcams videos about the topic. I chunk 8x8 hexes together in 1 mesh. Your videos and Catlike Coding's tutorial has been the most useful resources to me up to now :)
The game is looking great, keep at it!
I am doing your XCom style course right now, I'm learning a TON. Thank you!
That's great to hear! Keep it up!
I started a project using hex grids as the board a few months ago. Didn't take too long but got stuck on pathfinding around objects placed in a hex grid. A tutorial on that would be amazing!
Maybe look at Catlike Coding’s tutorial. It’s brilliant. I’ve adjusted the search algorithm to allow wonderful things :)
Thanks for this and all of your other videos, and especially your turn-based course. Really excellent, recommend it to anyone. I like the way you cut out your typos, as I really find people's errors distracting from the information they are trying to convey. Oh and I love your voice, can listen to you all day. Keep up the excellent work, and I wish you the best.
Hey man! I am LOVING your videos! But I took your advice and I feel like I'm finally leaving tutorial hell - I got your grid idea, that turned into this hexagon grid, and now turned it into an equilateral triangle grid! I'm going to implement the idea you showed in your A* pathfinding video for my triangles and then I could show you the result if you wanted. And oh, I haven't watched the dots video, so I might grab a bite off of that later too! Cheers!
Hey! I'm trying to do a triangle grid too, but I'm struggling with the rough coordinates for where the mouse position is, if I go to the points of the triangle, it sometimes messes up and rounds so it think it's in the wrong triangle
Mind if I ask how you did it?
@@GamesBySaul All this code that I sent you also have the A* logic for triangles. I'll soon work on finding every neighbor of a tile given the unit's range. I'll also work on the path finding logic for bigger units, aka units occupying more than one triangle, which means they need to get around obstacles going way around, oh also obstacles are not implemented yet.
Misleading thumbnail. I expected hex sphere.
I want to know, how it is possible to dive in new topics and get to know everything in such short time. It's so unbelievable how fast you go through mechanics in games or features and drop new content about it. Is there a secret to achiev that? When I am working my way through decomentations, than I need hours, to fully understand a topic.
You amaze me video after video and because of you I am learing so much for Game Dev and Programming in general. I mean just because of you, I know how to create unique artstyles for my games and tonnes more. You are simply the best:D
Code Monkey's just a chad. In both looks (he literally looks like the gigachad guy) and abilities.
But he did post 3 weeks back that he was researching hex grids.
@@Norbingel I know that but its still crazy that he manages to learn new topics so fast. And his abilities sems to be endless. Thats what I meant😅
The only "secret" is really just experience, that's pretty much it. The more things you build the easier it becomes.
Keep in mind I've been programming for almost 25 years and using Unity for almost 10, so when I research a new problem I already have a wealth of knowledge accumulated in my brain of similar problems or similar things that I've already learning, very few things are truly 100% new.
For example recently I researched Netcode for Game Objects, while the toolset itself was new, most of the concepts around it weren't. I've already worked with multiplayer in the past, my first Steam Game, Survivor Squad, had a multiplayer mode. So I already knew the basic concepts of Multiplayer, what is TCP/UDP, what is a packet, all about Delay, problems with NAT. I already know there are many tricky problems with synchronization, client prediction, etc.
All of those things were already stored in my brain, I didn't have to relearn them from scratch, only had to learn how the new toolset works, how the syntax is like, etc.
So don't get discouraged, keep at it, keep learning, the fact that you're here watching and learning from tutorials means you're on the right path, all that's left is time.
Best of luck in your learning journey and thanks for the kind words!
Hello everyone. I wanted to know how to make this Hex Grid. It is now a couple weeks later and I have completed both Builder Defender and Turn Based Combat courses. It cost me around $45, and I built my own Hex Grid. More importantly, I know what I am doing and how to change it. So thanks for the help. Now I go back to building my game.
I am also patiently waiting for the DOTS course.
Exactly the content I was looking for, however I have one more question (or improvement to ask for). You mention that this would be pretty easy to enhance to a 3d grid, how would you transpose this on a globe, as for example a planet type of object? The idea I'm pondering is to have a high level grid, and the more levels you zoom in the grid gets more detailed. I think I know how to do that part, just not how to calculate the hex grid for the surface of a planet...
Aren't you using regular hexagons? In that case the vertical size and the horizontal size aren't actually the same and using the same cellSize for both should yield a slightly wrong vertical displacement for the rows. Maybe it isn't noticeable with the thick hexagon lines. Or maybe I'm wrong lol.
Let me take the chance to say thanks for all the videos!
Yup I intentionally made them slightly squished making the width == height, personally I think they look better this way as opposed to the more regular hexagons which have a pointier top
@@CodeMonkeyUnity Now I know why my grid's height was off 🤔
@@CodeMonkeyUnity Hey :) How do i fix the code if i am using a "normal" Hexgon? My Hexgons are not connected on the X and I am not able to find the Solution...thanks for they vids and for ur help!
@@RL_Kaizen Hello I hope its not too late.
You need to calculate the Apothem of the hexagon (actually 2x of the apothem) and use it on your X axis. To calculate use:
MathF.Sqrt(3)/2 * cellSize
I store it in the base class as float cellShortSize and use it for x calculations.
@CodeMonkeyUnity maybe you can add this to description or something.
Hey! I was excitedly waiting for this one!
You is a real one homie! I made a really crappy version like 1 year back and haven't touched it since so this is really nice 🥰
Если клетку (квадратную) разбить на 4 части, то сместив объект на пол клетки можно добиться такого же эффекта как при шестиугольниках. Или просто квадраты в ряду сдвинуть на полквадрата. Можно ещё попробовать координатную сетку изменить - использовать не 90° а 120 или 60. Если посмотреть на шестиугольную сетку, то мы увидим что там 3 прямых оси. Естественно у каждого способа есть свои заковыки и причуды, которые придется решать. Ну а по хорошему, это все должно быть уже встроено в движок.
I literally started a civ Style strategy game Today and i wanted to have a hex grid system just like civ and then this showed up...
The timing is epic
Awesome. I build a hex-based grid system that works with Unity's tilemap for 2D level building. Took months for me to build a system that was seamless with build-in Unity tools.
I recently started a building/automation game using planets and space and I think a hex sphere would be absolutely perfect, is it hard to apply it for something like that or would that be too much for a comment reply?
Thank you! I love your videos and you and your content inspired me to start game design!
Thanks for the awesome tutorial, Code Monkey!
Do you cover Addressables in your course(s)? That's the Unity feature that I'd like to learn. I want to pull my assets out of my main project and speed up compile time.
Another vote for addressables
Yup I do cover it in my Ultimate Unity Overview course, added it in the last free update covering Addressables Local, Addressables Remove and Cloud Content Delivery unitycodemonkey.com/video.php?v=a6N9Bawtdns
How would you expand this grid system to also apply to walls/3d space. For example, say you wanted to make a space for a spider that can walk on walls and ceilings on a grid. What method/s would you suggest to expand this system to also place the grid (continuously) on those surfaces?
Your tutorials are wonderful, many of my doubts were resolved, you would be encouraged to make a tutorial of a 2D isometric grid. Thanks for your tutorials. good work
Great video. Thanks. I noticed that there was no checking for non-existent neighbours. If you pick the hex at 0, 0, then it's only going to have 2 neighbours, right.
The logic is all based on math so even though grid position -1,-1 does not actually exist it can still be converted into a world position and used in the distance check.
Hello Code Monkey. Have you checked whether the calculation for negative indices (-1,1)(-1,-2) will work? By replacing Floor with Round, it seems to me that you have lost this opportunity.
This Grid System never has negative values, it always starts from 0,0 so I haven't tested that but I assume the logic works just fine, Round/Floor in Unity should work the same in positive/negative values.
Thanks again. This is why you are amung the best. Just finished your course and was messing with hex grids.
Amazing stuff. Can you make a tutorial on how to create a terminal like in Hacknet?
project files dont have the files which you copied the code then the tutorial.im having hard time to figure it out.please help, anyone?
Hey Code Monkey, first thanks for the awesome packages and video tutorials. Second there is a pink square behind my hexagons and I cannot get it to go away, when I run the game it is just a bunch of squares. How do I get the hexagon shapes to show up in the game rather than a bunch of pink squares. Thanks in advance as I can already tell you are a dedicated guy and love teaching/helping people along their game dev journey.
nevermind, I figured it out just had to change my project setting to use URP as the renderer. Thanks anyways, I will come back if I have more issues!
Yeah pink means shader error so yup it would be related to the render pipeline. I'm glad you like the video!
I saw Dungeon Masterpiece in that search result 👍
Hi, thanks for the video. Do you plan to continue your Udemy turn-based course as well?
Yup, these Hex videos were made while researching hte topic for the course, I'm working on hte free expansion and should be out sometime this month
Cool video! How does this compare to the existing hex grid tile system in unity?
That system is mostly meant for visuals, placing down hex tiles and so on
This system can be used for visuals but is mainly used for logic, each grid position has a grid object which you can use to store whatever logic you want, not just visuals.
@@CodeMonkeyUnity cool! Thanks for answering 😊
The only reason click this video is the order to see it see how to make plans with hexagon tile map.
And little with I know wean press the the show normal hexagon tile map on,
Not sphere like the thanb nail.
What do you mean "How to make plans"?
To make a sphere you would manually position the vertex positions on a sphere unitycodemonkey.com/video.php?v=11c9rWRotJ8
Thanks!
Thanks for the super thanks! I hope the video helped you!
Could you please show us how to implement the tilemap to the hexgrid? I've been trying for days to connect those two tutorials but I made a huge mess!
Look at the Mesh video and first just handle the logic on how to draw a Hex mesh. unitycodemonkey.com/video.php?v=11c9rWRotJ8
Once you have that it's simple to add that shape to the tilemap
@@CodeMonkeyUnity I will try to do so thank you for the tip
How would you outline a collection of tiles like the city influence borders in civilization?
You need some sort of list of the tiles you want to select, then do some logic to find out which of the points in the hex are outside (meaning not neighbours of another selected tile)
Then once you have that list of points you could just dynamically create a mesh unitycodemonkey.com/video.php?v=11c9rWRotJ8
@CodeMonkeyUnity thanks for the reply! That's what I'm trying to do, I'm just struggling to figure out how to actually do the logic
Very good work! Great video! =)
i dont like hex grid. but man, you made it sound insteresting to make.
The hexisphere is misleading. I watched the whole vid and never saw him make it.
7:00 Why are you not just refactoring the class names instead of changing every single one from hand?
What do you mean ? I did just change the class name, to keep both classes
@@CodeMonkeyUnity right, my bad.
now how do I make a hex sphere (with 12 pentagons, of course) like in the thumbnail?
You could keep the logic flat exactly like this, and then just apply an offset to the visual to make it round
@@CodeMonkeyUnity did you use a shader to do that? something like what is done for the Animal Crossing game with the curved world? I've been trying to make a hex grid sphere but from what I've discovered its mathematically impossible to do without a dozen pentagons showing up.
A easier method for figuring out the coordinates is to think of the hew grid as just being a square grid in isometric perspective. Then you can travel along the x and y axis to travel in a straight line, then you simply travel "diagonally" to get the third possible axis for the hexagons.
I did see another method which I believe is what you're talking about, it was making the hex positions on a 60º angle rather than like I did by trying to make the entire grid square shaped.
I didn't go with that approach because I wanted to have a rectangular shape for the whole grid but that one does sound like it simplifies some things.
Why don’t you use the TileMap provided by Unity. They provide API to do a lot of the basic stuff
Because that tilemap is meant to hold sprites, not logic. With this Grid System you can store any logic in any grid position, like checking if the position is walkable or if there's a building on top of it unitycodemonkey.com/video.php?v=Cdcn6uK9gPo
@@CodeMonkeyUnity You still can have a business Logic grid just like you do, with grid position, like checking if the position is walkable. One is visual Tilemap, the other one is grid business logic, like you have
I imported these files just to look, and it wrecked by project. Don't know why, but Rider wouldn't recognize any tilemap functions anymore. Not a big deal, I just looked at what I needed to look at and deleted the files. But still.
What do you mean "wrecked your project"? The only way I imagine that could happen would be if you had project files from a different old video which were replaced by these ones. Or maybe you happen to have exactly the same folder structure and filename as something that was imported.
Nothing here should touch anything in your own files
how does unity convert pixel to size i got a hexagon sprite 120 width x 140 height in pixel
if i math the size like code monkey said 75% i end up with offset of
width = 1.6f;
height = 1.866f;
they are spread very very far apart very close do i get with:
1.2155f; width
1.05f height
either the tiles slightly overlap or they slightly are off
If you use a 3D Quad it will have whatever size you give the Scale, regardless of how many pixels are in the original texture. The texture size in pixels does not matter.
If you use a 2D Sprite on a SpriteRenderer, the size is defined in the Texture Import Settings - Pixels Per Unit
@@CodeMonkeyUnity
100 pixel a unit seems about right
the first 4 tile are visualy spaced correctly same from the coodinates
the 5 tile looks slightly offset to much or to little visualy the coordinates are correct
width only height looks fine
looking for idears
in your first vid about the square grid you had this code to draw a square.
for (int x = 0; x < gridArray.GetLength(0); x++)
{
for (int y = 0; y < gridArray.GetLength(1); y++)
{
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
}
}
Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
I if you converted this code off cam. if not no worries. thank you for the video!
Those are debug lines just to help visualize the grid but they won't be visible in a final build.
If you want to see them in game you need to use meshes or sprites
@@CodeMonkeyUnity Ok thank you!
It's not 75%, it's √3/2...
Will this also work on a touchscreen phone?
Sure, this system is completely separate from whatever input method you want to use
what package i must intast aso i can use GridXZ??? i get this error => Assets\Scripts\TestingHexGrid.cs(11,13): error CS0246: The type or namespace name 'GridXZ' could not be found (are you missing a using directive or an assembly reference?) also u dont send email so i can verify the acc on your page and i cant download progect files..
It was made in a previous video linked in the description, and it's included in the project files
Check your spam folder
Que onda bro, espero que no te moleste mi comentario. Soy luciano, tengo 20 años, y a mis 17 deje la escuela secundaria para dedicarme a estudiar programacion de manera autodidacta con cursos, y videos en youtube(especificamente desarrollo de video juegos). Para mis 19 años despues de pelearla muchisimo, y mucho esfuerzo, me becaron en la universidad lider del desarrollo software de argentina(Image Campus), trabaje en varios estudios de desarrollo indie, y actualmente voy a recibirme de desarrollador full stack con ArgentinaPrograma, y otras capacitaciones en conjunto. Todo esto lo hago para sacar a mi mama del barrio para serte sincero, somos muy humildes, y mi unica herramienta es mi cerebro, y mi pc. Aparte de todo esto, intento subir de a poco con youtube, pero se hace muy dificil siendo un tema de tan escasos conocimientos el pais, simplemente me gustaria pedirte si es posible que fijes mi comentario, o le des un corazon para que mas gente pueda llegar. Lo hagas o no, muchisimas gracias por leerme, y regalarme tu tiempo. Un abrazo a todoos
Sounds like you're on the right path, keep at it!
@@CodeMonkeyUnity Thankss !!!
creative comnt...........................Thank you!!!!!!
10/10
Hey can you help ke out on something different from this video?
I would like you to make a video where an player has to collect a cube, which spawns at another position after being collected
When the cube is collected it adds score and spawns at another position in the room (infinitely) without stopping
For collisions a simple OnTriggerEnter works unitycodemonkey.com/video.php?v=Bc9lmHjqLZc
Little overboard on the course promotion, I love the tutorial but I already have the course and it was painful to have it advertised like 4 times, like I have youtube premium for a reason bro. If you're going to sponsor (even self sponsor) in my honest opinion it should be one time not 2+. As always thanks for an excellent video, just felt like something needed to be said.
I mentioned in the intro when talking about why I researched this, then this video didn't have a sponsor spot so I added my own which mentions the other courses and finally another mention at the very end after the video is over.
The only difference compared to "regular" videos is this video was specifically made to research that topic for the free update to the course, beyond that the format is exactly the same, intro, courses ad, free video, courses ad outro.
It feels to me that a 21 minute free video with just 1 minute talking about my courses is a pretty reasonable ratio.
The simple reason as to why these free videos exist is because people buy the courses. If I didn't mention the courses anywhere and no one knew about them and no one bought them then this channel would die and no one else would ever benefit from free videos.
I love to watch you work but you're working way too hard. For instance, when you create an instance of your hex tiles you could be placing them into a 2D array and you will have the x,y for all tiles without all the rounding issues where you need to check all surrounding tiles. Also you can check when a mouse if hovering over any prefabs, etc.
Yeah... Generally agree, but a good hex coordinates uses (x,y,z) coordinates. Makes pathfinding much easier. And z ain't the 'height', it's really a vector3 2d coordinate
Could just have an enumerable GetNeighbors method on the HexTile class IMO. Also for proper path finding, you need a traversal cost defined on each tile. (Most tactics games have that, anyway; where units move "slower" over some terrains than others, and your path finding should take movement cost into account).
@@BrainSlugs83 Wow. I guess I just know things about how to optimize from an intuitive viewpoint because you all seem to like doing the work regardless of the number of steps. LOL.
Not sure what you mean, the grid does use a 2D Array but the array index does not tell you anything for how to convert a world position into a array XY index.
@@CodeMonkeyUnity Yes, it does, through each of the tile objects, you created when you instantiated the prefab. You throw the object away, but you should put the object into a 2D array because when you can convert from x and y grid cells into tiles and vice-versa with a bit of engineering. You created a problem and then forgot that you created the problem, then you engineered around the problem as if you had not created it. Maybe you don't like yourself. I have been coding for many years, and many years ago, I learned how to do myself a favor when writing code. Maybe I don't hate myself. Look at it this way. You want to convert from grid x and y into world Vector3, yes? Place the hex tile objects into a 2D array, and now you can convert from grid x and y into World Vector3 because all tiles know their own transform. To convert the other way, you place the tile transforms into a 2D array, then iterate to determine if a Vector3 falls inside a collider (this assumes you gave all hex tiles a collider). You can approximate to determine which specific file to interrogate to save time; however, this is only a concern for very large tile maps and not smaller ones. For huge tile maps, you can either build a state machine to chew on the problem using the update method that fires once for each frame then fire a delegate when the tile is found or use Unity Job System that does the same thing. Either way, you need to learn to be nice to yourself rather than making yourself do more work than is required. Also, you need to learn how to balance RAM usage against code usage. Using more RAM can result in less code or vice-versa, and both must be balanced. In any case, for huge tile maps, you would not create all the prefabs for all the tiles upfront; you would create only those immediately around the player or the camera and destroy the rest as the player or camera moves. Hoping this helps.