Тёмный
No video :(

Custom Tilemap in Unity with Saving and Loading (Level Editor) 

Code Monkey
Подписаться 537 тыс.
Просмотров 75 тыс.
50% 1

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 204   
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Let's take our Grid System and make a Custom Tilemap with Saving and Loading so we can easily share Levels! 🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
@Ely_Dev
@Ely_Dev 4 года назад
So good
@technofeeliak
@technofeeliak 4 года назад
Your videos are always interesting but very hard to follow.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
@@technofeeliak What couldn't you understand?
@klarnorbert
@klarnorbert 4 года назад
Why don't you just use Tiled? It's a free full blown application for building tilemaps.
@baka6479
@baka6479 3 года назад
Does it work witth unity 32 bits
@chengkuangyu
@chengkuangyu 2 года назад
I started following your channel and learned a lot of things I didn't know before. Thanks for all the detailed explanation which helps me to make my codes cleaner and easier to use. I used to hard code all the logic and waste tons of time on unnecessary places, and now I start to use generic class and namespace to store methods that can be reused in other projects, plus some cool system features I learned from you. It's great to find an awesome mentor like you on the internet.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
I'm glad the videos helped you! Thanks!
@andrewshandle
@andrewshandle 4 года назад
I like this because it makes it much easier to build levels outside of Unity and just import them. As long as the JSON is in the right format, it'll just work.
@uniquehedghog
@uniquehedghog 4 года назад
you should make a tutorial for isometric editors with elevation like hills and cliffs
@tomasgammister5776
@tomasgammister5776 Год назад
I am tormented by vague doubts))) 😆 now I will try )
@alhu5514
@alhu5514 4 года назад
I wonder how does the constructor at 3:46 does work? new TilemapObject(grid,x,y). At this time grid should be null. But with finishing this line the variable grid is overwritten. But the grid of the tilemap object is still pointing to null or how is the reference changed to the current grid? (I'm not sure about wording here.. )
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Yes in there it should be new TilemapObject(g, x, y); to use the grid that is passed in the function and not the one in the field. I fixed it later but it gets cut off in the video because that line ended up way too big.
@Jaydouble-u
@Jaydouble-u 4 года назад
@@CodeMonkeyUnity Thanks for the comment though, following this tutorial with sleepy eyes because the learning value is so addictive, can't stop, but I had nullpointers at runtime. This was the problem. Thank you for this series by the way!
@Michal005
@Michal005 4 года назад
THX this comment helped me
@valourcat3164
@valourcat3164 2 года назад
Helped me too... this was driving me mad!
@AlexJazzEEk
@AlexJazzEEk 3 года назад
hello/ i imported the Project files and Utilities from package in link, and when i run the game i just see gray screen. Can you help me? what can be a problem?
@BrokenPuzzle03
@BrokenPuzzle03 3 года назад
When you create the constructor for the tilemap on the function part you send as a parameter grid. when it should be g. Just letting other know since it took me a while to figure out.
@MrJimmyAinsley
@MrJimmyAinsley 2 года назад
Thanks for pointing it out! This was keeping me from going forward with the rest of the tutorial!
@MarkMcArthey
@MarkMcArthey Год назад
If, like me, you tend to use 'var' for most variables you may notice that your Ground and Path sprites aren't appearing correctly at around 16:05, then be sure you have the textureWidth and textureHeight variables declared as float. If not, they will become int values and will not contain the correct normalized values to select and display the sprites. It took me a bit to realize so hope this helps someone!
@gabypounou3793
@gabypounou3793 Год назад
for me, the tiles are still displaced... any idea why ?
@xenaedits551
@xenaedits551 Год назад
@@gabypounou3793 I had this problem too, for me the issue was that the testing and tilemapvisual game objects were not at (0,0,0)
@Crystan
@Crystan 4 года назад
So, the one downside I can see with this implementation is that it only works at runtime. Is there a way to get similar functionality as the Unity tilemaps where you can build a level in the editor using this grid and then save the information with the scene? I've been trying to develop my own custom tilemap for this purpose and keep hitting brick walls. The Unity tilemaps are far too restrictive and the given tools are cumbersome to say the least.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Use the Attribute [ExecuteInEditMode]
@Patrickblox
@Patrickblox 2 года назад
Hey Monke, is there any chance of getting this to work with tilemap chunks and auto-tiling?
@NeverEverTM
@NeverEverTM 4 года назад
i ended up creating my own system, but the tutorial help me anyways :D
@heyitsapogee
@heyitsapogee 2 года назад
Hey Code Monkey - I'm interested to hear how you'd implement collisions into the tilemap? What if you were creating these tilemaps for players to explore and didnt want them running through wall tiles?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
You could dynamically place a BoxCollider on each Tile position that you wanted to block. Or you can just make another Grid System to hold the walkable state, and when the player moves ask the Grid System is the player can move there, so pretty much just like the Pathfinding system unitycodemonkey.com/video.php?v=alU04hvz6L4
@heyitsapogee
@heyitsapogee 2 года назад
@@CodeMonkeyUnity Thank you for such a quick reply, great ideas to consider 😄
@FullMe7alJacke7
@FullMe7alJacke7 Год назад
It's not shown in the video, but towards the end of adding saving and loading, you also need to add the Tilemap parameter to the calling of the SetGrid function. It threw me off I didn't see it mentioned in the video, so I went back and rewatched it because I thought I missed something.
@bierkules2608
@bierkules2608 4 года назад
Quick questions: What would be "better" a big mesh with all the sprites like in your tutorials or game objects with sprite renderers for each tile but with frustum culling to cut all the not visible tiles away and pool older ones? The second question would be: How could I make smooth transitions between the tiles without drawing every transition, I want to lay the different tiles on top of each other.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
A big mesh is a lot more performant. You can easily render 1000 tilemap quads, very difficult to get 1000 sprite renderers. For smooth transitions you could draw the transitions as half transparent and put them on another tilemap on top of the base one.
@bierkules2608
@bierkules2608 4 года назад
@@CodeMonkeyUnity I almost thought so. But unfortunately you seem to have updated your utility classes, they are no longer congruent as in the video. So I wasn't able to follow the video with your utils. Thanks for the quck anwser!
@bierkules2608
@bierkules2608 4 года назад
Nevermind, I just followed your other videos and created the utils by myself. Keep it up great work! Hope you stay safe and healthy tooo!
@bierkules2608
@bierkules2608 4 года назад
Me again! Puuh I'm stupid! You uploaded the MeshUtils but it was in a diffrent folder.. lmao.
@oystudios3052
@oystudios3052 4 года назад
I am having some difficulties at 5:07, when I tried out the script I got a nullreferenceexception: NullReferenceException: Object reference not set to an instance of an object Tilemap+TilemapObject.SetTilemapSprite (Tilemap+TilemapObject+TilemapSprite tilemapSprite) (at Assets/Scripts/Tilemap.cs:48) Tilemap.SetTilemapSprite (UnityEngine.Vector3 worldPosition, Tilemap+TilemapObject+TilemapSprite tilemapSprite) (at Assets/Scripts/Tilemap.cs:21) Testing.Update () (at Assets/Scripts/Testing.cs:20) And I can't for the life of me find where it comes from or how to fix it, help would be very much appreciated.
@oystudios3052
@oystudios3052 4 года назад
Update, I found the problem and made a makeshift solution but I would love to know what I did wrong because it is messy code, my problem is that the variables grid, x, and y are never assigned. I followed the tutorial step by step but I still must have missed somthing, thanks in advance.
@oystudios3052
@oystudios3052 4 года назад
I seem to have fixed the problem but I have no idea how...
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
You mean when creating the object? Those variables (grid, x, y) are set in the TilemapObject Constructor 3:02
@oystudios3052
@oystudios3052 4 года назад
@@CodeMonkeyUnity Thank you for responding so quickly! Yes, I think I forgot to set the grid value because that was the one that was null. I have finished the tutorial now but I have another problem. In between the tiles you can sometimes see lines, after some research I found that this was also a problem with the tilemap from unity. But all solutions I could find were to add pixel bleed (wich I am not sure how to add) or something else you can only do in the built in unity tilemap system. Do you have any idea how to fix these lines? Thank you so much for your help, I would not have been able to make my current project without you.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
@@oystudios3052 Maybe try enabling Anti aliasing
@felix393
@felix393 Год назад
Just want to say: thanks for all the amazing videos! Took me a bit of tinkering to get everything right but that thought me so much more than any of the superficial yt videos other creators put out! Really love the fact that you don't use the unity standard functions for everything bc those are really limited when it comes to making something truly custom. One question though: currently the enum is implemented in the tilemap object and is then serialized in the tilemap visual. what would you suggest to do for multiple tilemap sets (i.e.: ground, props, walls etc)? create a custom tilemap object for each and everyone? Or forego the specific naming altogether and just name the enums after quadrants of same sized materials? Would rly appreciate your input on this!
@fordgt500ss
@fordgt500ss 4 года назад
Please tell me that he speeds up his video while coding? Lol, otherwise I need to go crawl into a corner and cry.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
I write fast but not that fast!
@verified_tinker1818
@verified_tinker1818 3 года назад
Practice!
@maxdart
@maxdart 4 года назад
Wow, excellent! Any chance to do something similar with isometric tilemap?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Yeah Isometrics and Hex maps are something I'd like to look into.
@Toopa88
@Toopa88 4 года назад
@@CodeMonkeyUnity Pathfinding for isometric maps would be really nice.
@lolownq
@lolownq 4 года назад
@@CodeMonkeyUnity Hey CM i'm new here but would love to show you my implementation of your grid for use with isometric maps, i currently use it alongside the default tilemap to make both drawing previewing and interactions easier (i use procedurally generated terain, so all of the tiles come from code anyway)
@77eight8
@77eight8 Год назад
Hello Code Monkey! I have a question. How do we convert this for a hex grid like in the latest videos? I tried to use this for my hex grid but the tilemap is not created correctly. Thanks in advance and have a nice day!
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
You would need to modify the Mesh code to create a Hex shape. I covered the math for getting all the hex points in this video unitycodemonkey.com/video.php?v=dqframYHfws Then you would use those points as the vertices and set up the triangles
@77eight8
@77eight8 Год назад
@@CodeMonkeyUnity Thank you, I will try to that!
@ShawnRay
@ShawnRay Год назад
So I think I’m going to use scriptable object to make a 3D dungeon. This should work pretty well as long as I don’t try to overlap pieces. The scriptable object will just save the prefab and height.
@nicholaspitti8171
@nicholaspitti8171 3 года назад
Hey CM do you reccomend using this grid system for inventory and quick item slots? Or should I just use the other tutorial you made?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Depends if you want the inventory to have "fixed" positions or not. I also covered a inventory with a grid system here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-fxaDBE71UHA.html All the positions are fixed, whereas the other inventory has a virtual list so its unlimited.
@maviekran6942
@maviekran6942 3 года назад
How can i do this with job system ?
@GameWithAshish58
@GameWithAshish58 4 месяца назад
Sir how can i use this base class to use in my 2d farming game.
@LesusX
@LesusX Год назад
Hello! I followed the steps until 4:50 but when I click on the Grid I get an exception (NullReferenceException: Object reference not set to an instance of an object Testing.Update () (at Assets/Scripts/Testing.cs:17)) Any ideas?
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
@Gytimaru
@Gytimaru Год назад
if you're the same as me, he didn't show it in the video but in the Tilemap.cs, in the Tilemap constructor it needs to look like this: grid = new Grid(width, height, cellSize, originPosition, (Grid g, int x, int y)=>new TilemapObject(g, x, y)); but in the video, he shows: grid = new Grid(width, height, cellSize, originPosition, (Grid g, int x, int y)=>new TilemapObject(grid, x, y)); I'm not sure why he doesn't either explain the change or show in the video when he fixes it
@vrtech473
@vrtech473 4 года назад
Can you make a tutorial about streamable enormous grid map? 10000x10000 or combine with ECS ? Thanks !
@LivingToPay
@LivingToPay 4 года назад
I'm sorry for this noob question, but how do I start to make my Grid from the bottom of the camera? Mine always starts at the center, and grows to the top right corner, so I can only a quarter of the grid.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
It starts where the GameObject is located so just move that game object Alternatively expand the script to add a simple Vector2 offset
@vladsavenco9609
@vladsavenco9609 7 месяцев назад
How would you go about placing a "tile" that is made out of multiple tiles? I was trying to make some sort of building system and was looking at placing entire rooms at the same time. Is it similar to your building system video but in 2d?
@davidzaslavsky2076
@davidzaslavsky2076 3 года назад
hey small problem when I click on the square its not changing from none to ground the part that it is not working is the SetTilemapSprite update fixed it
@collinfarrell9718
@collinfarrell9718 3 года назад
Has anyone found a solution they like for determining and updating the transitions between different tilemap types, such as corners and edges of dirt up against path or grass tiles etc?
@jasonwojcik6137
@jasonwojcik6137 3 года назад
It won't help you when using the CodeMonkey tilemap class, but if you use the Unity tilemap tool and download/add the 2D Extras package, you can use Rule tiles to control auto-updating of tiles to respond to other nearby tiles.
@pepsipwns666
@pepsipwns666 2 года назад
Any solution to this? I have ideas .. but seems tricky... Perhaps multiple passes over the grid to generate the joining parts after by checking neighbours? Would love your help @Code Monkey
@paritoshmishra2572
@paritoshmishra2572 3 года назад
My tilemap cells are larger in size in compare to grid cells size. Any idea why that happens.
@dragonlord1935
@dragonlord1935 3 года назад
Hey, I just wanted to know if there any significant performance differences between your tilemap system VS Unity's built-in tilemap. I'm thinking about digging into some large scale procedural generation and this system seems practically perfect for that, but at the same time, I want to know if there's a significant performance difference between the two because then I'll have to choose the built-in system instead to decrease the performance hit (even though jerry rigging procedural tile generation in the built-in will be more difficult in the short term). Which do you think will be better from an optimization perspective? This or built-in?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
I'm not sure since I never tested them side by side, I know this one is very performant since it's based on a single generated Mesh. Do a quick prototype to test it. But unless you have really small tiles I doubt there would be any performance issues
@dragonlord1935
@dragonlord1935 3 года назад
@@CodeMonkeyUnity Ah...see you absolutely nailed the problem. I'm trying to do a tilemap similar to the game Starbound (give it a quick search if you haven't seen it). The problem is that each tile in Starbound is made up of four 'sub' tiles. That obviously means that each tile is 1/4th the size of a regular tile but consequently there are 4x as many tiles in the world (It results in very smooth terrain almost to the point where sometimes it doesn't even look like a block game). I'm sort of stuck on how to make a system like this which is actually efficient. I know it's likely possible through the use of some trickery but I'm drawing a blank. I know this is a bit off topic here, but how would you go about making a system like that, theoretically speaking?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
@@dragonlord1935 Oh right for something like that you definitely need a very performant approach. The biggest challenge with that is more with keeping the state of all those nodes. If I were making that I would probably use my system since it was made specifically to work on top of my Grid class which would be perfect for that type of game. But with that scale you cant have just a single Grid for the whole world so one very tricky challenge is how to break the world into tons of separate grids and handle any connections between them.
@dragonlord1935
@dragonlord1935 3 года назад
@@CodeMonkeyUnity Do you by chance know of a way to only load parts of an object? So essentially, only loading the tiles around the player into active memory while keeping everything else in a "lazy" data only format? how would you only load parts of a mesh? Is that even possible?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
@@dragonlord1935 You can't load parts of an object but you can organize your world into multiple objects as opposed to a single one. So instead of a giant mesh occupying the whole entire world you split the world into say 100 meshes and only show the 5 nearest to the player.
@its_gerryz14
@its_gerryz14 4 года назад
Please help me! Im writing the code at 1:41 ive checked literaly letter by letter, because it throws this: error CS0308: The non-generic type 'Grid' cannot be used with type arguments even when i downloaded the script (allone) from the project files, it still threw that error with some others.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
You need to be using the Grid class made in the previous video, not the Unity one ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8jrAWtI8RXg.html
@matejemmer6284
@matejemmer6284 4 года назад
@@CodeMonkeyUnity I'm using it and it still doesn't work :/
@itsmii7348
@itsmii7348 3 года назад
Hello, I tried making the tilemap account for variable tile sizes, and therefore render the quads at different sizes, but it leads to overlaying quads. Is there a way to control the rendering order of individual quads? I tried sorting them by the Z axis and also by flipping the order in which they're updated, but nothing seems to work. As it stands right now tiles higher on the y axis always render in front. Thank you for all hypothetical responses!
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
The order is based on the vertices array. vertices[1] will show up on top of vertices[0] The best approach might be to have a base tilemap, and then make a second one on top that only contains the tiles you want overlayed.
@hydraorc1
@hydraorc1 3 года назад
I don't understand how do you make your tilemapvisual to be visible in play mode? I added the scripts and the visuals but still cannot see the black grid that you have in your video
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Pause the game while running and look at the object, has the mesh been created?
@nicholaspitti8171
@nicholaspitti8171 3 года назад
Click on TilemapVisual object that you created in Object Hierarchy make sure the transform x and y are set to 0). The visual will then appear on top of the text grid when you do the click to change from None to Ground.
@manflu3891
@manflu3891 Год назад
Hi, I can't figure out how to this to work in a 3D environment / along the z axis and not the y? When I try to fiddle with the MeshUtils I can't get it to work. When I just use your code as is, then all the vertices "stand upright" but along the x and y axis. I have tried looking through your 2d to 3d video, Mesh and Grid Building (and through your project files) but I can't find a solution.
@manflu3891
@manflu3891 Год назад
The solution: create a GetWorldPostion where you return z as the y value and pass that to the tile map. This will create the entire tile map as if it was 2D. Then simply rotate the x 90 deg in the editor on the tilemapVisual gameobject. This will create a tile map along the x,z and it works with the Mouse3D positions.
@sofianelamine9434
@sofianelamine9434 4 года назад
My game 2D is love date i learn with this channel
@ASMRcu
@ASMRcu 4 года назад
Another Awesome tut......sir please make a video on Damage Indicator for FPS/TPS
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
I've done a video on Damage Popups, to make it work in 3D just rotate the Text towards the camera ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-iD1_JczQcFY.html
@ASMRcu
@ASMRcu 4 года назад
@@CodeMonkeyUnity yes sir i view this its just popup.....i want to detect from which direction the player getting shots...just like pubg.....
@black_squall
@black_squall 8 месяцев назад
Unity's Tilemap not having a simple hide/unhide feature for the tiles was ridiculous. I guess i'm building my own now :(
@jellohunter7981
@jellohunter7981 3 года назад
Is there a reason you would use this over unity's built-in tilemap system?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
If you want more control over how the Tilemap works or is rendered or if you're already using the same Grid class to handle logic objects. If all you want is a basic visual Tilemap then the built-in works just fine.
@jellohunter7981
@jellohunter7981 3 года назад
@@CodeMonkeyUnity Thanks for the response! :P
@tomasgammister5776
@tomasgammister5776 Год назад
and it will work like saving the level and the game itself with loading the game back?
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
Yes
@pepsipwns666
@pepsipwns666 2 года назад
I've been following your great tutorials around the grid system & pathfinding, thank you so much for these tutorials! This is my next hurdle. My first question is should I make another grid entirely for this tilemap, or edit the PathNode object to include the sprite stuff and just have one grid of objects? Second question: I have my tilesets set out seperate for grass, dirt, water, with corners, sides, etc for each, I've imported them using normal unity tilemap and cutting them out with multiple on sprite editor and painting a scene just for testing purposes. But whats the best way to use these or turn them into what you've done? Should I have all water/grass/dirt on one big mesh renderer thing and use a vector to select which one? Is there a smart way to group them by grass/dirt/etc?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
Making one grid to handle pathfinding and another separate one for the Tilemap is the better approach. Yes, with this system instead of slicing the sprites directly in the sprite editor, you just have one big texture and you "slice" it manually by defining the UV Vector2s for each tile.
@pepsipwns666
@pepsipwns666 2 года назад
@@CodeMonkeyUnity Thanks for your response. My tileset is quite complicated with around 6-10~ tiles for each dirt, grass, water with all the corners & joining edges etc. What would be the best method for making these joining sprites work? Some kind of multiple pass system? Where it draws the basics dirt/grass tile first then does a second pass checking neighbours and changing them accordingly? Edit: Do you think I would be better using unity 2d extras rule tiles? And generating a grid of rule tiles? I assume this will be more taxing, but if just loading a map on initial game load is that ok? OR will it cause gameplay lag?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
​@@pepsipwns666 Making edges join smoothly is quite tricky, you could have a second tilemap on top of the base one and on that second tilemap you would draw the edge smooth texture for all combinations which in that case would be quite a lot. Best approach would probably be multiple tilemaps for each type and make tiles for the transitions that fade away. So the water tilemap would be on the bottom, then the grass above that one with a grass tile that smoothly fades away which would look like it fades into the water.
@pepsipwns666
@pepsipwns666 2 года назад
@@CodeMonkeyUnity Thanks so much for your responses really giving me food for thought. To give you an idea of what I'm trying to achieve, its a top down game that I would like to randomly generate maps for (on initially loading your game, so doesn't have to be super quick). It doesn't need to be massively random just different enough... So your saying one tilemap per type (water, dirt, grass) etc, have it draw the water first (entire map covered in water?), then next tilemap draws dirt and can detect when its placing the last tile on x/y axis (the edge/corner tiles) and place edge sprites accordingly? How/where/when would I detect this? xD My other idea was to generate entire tilemap of water, then run another pass over the same tilemap changing 'chunks' of it to grass / dirt sections. Somehow 'saving' blocks of dirt/grass as preset areas of dirt/grass? and just blopping them about? If that makes sense... maybe if I could draw/save some chunks and have them spawn randomly ... Edit: Would I be saving myself a lot of hassle using the Unity 2d RuleTiles? I was hoping I could make use of the MeshRenderer system you have going... but it seems very difficult to involve smooth edges... I have managed to create a 1000*1000 randomly generated map with 'center' tiles of dirt/grass/water using your MeshRenderer system & UV00/UV11 to select sprites. I've thought about looping over it again with a SmoothMap() method, checking every tiles neighbours and seeing if they are a different tile from itself. Thats about as far as i've got... I'm not sure without writing tons of if statements how to detect when to replace the tile with a corner/side piece etc...
@pepsipwns666
@pepsipwns666 2 года назад
@@CodeMonkeyUnity Hey Dude, Thanks to your assistance I got it working, I have multiple layering tilemaps, all with rules for each joining tile on the edges etc. Its working great! I have another issue now though. I have been working on a 100*100 grid as I sorted this out, its perfect on that, but now when i changed to 200*200 for example, it seems like only the height is increasing and the width is still 100, anyway thats my assumption. The sprites look all squished and bizarre.
@DeveloperJake
@DeveloperJake 2 года назад
you’re an amazing person
@felix393
@felix393 Год назад
Is there an easier method to fix the texture scaling than adding padding to all textures (see at 16:34)? I assume by adding padding you mean editing each texture to have padding around it manually. Or is there some way to do that in code? It appears that this happens when creating a material from the a texture. The edges are no longer pixel perfect but are blending into each other. The main issue with the padding is that then you can't have pixel perfect tiles can you? Never mind, my issue was setting the filter mode in the texture to anything but the correct one. Which is none ;) i.e. "Point (no filter)"
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
If you don't enable filtering and don't enable mip maps then yeah it will be pixel perfect, but that method is only suitable for pixel art games where the sprite size doesn't change. If you have non-pixel art or zoom in/out then you really need that padding.
@lyeuhm
@lyeuhm Год назад
Would there be a reasonably ... "simple"? way of building colliders into this to prevent players going through walls? You might already have a video on it but I couldn't find anything
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
You could add BoxCollider2D's to each tile and combine them with a Composite Collider That's exactly what the built-in Tilemap does
@thebiggestmaninexistence6239
@thebiggestmaninexistence6239 4 года назад
First my guy
@GlyphicEnigma
@GlyphicEnigma Год назад
My visual grid has huge gaps in between each cell but my code is exactly how it is in the video. How do I fix this????
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
Check how you are creating the mesh for each grid position, maybe you're using half the cellSize
@GlyphicEnigma
@GlyphicEnigma Год назад
@@CodeMonkeyUnity/videos In the method call for adding the quad, the position is set to [grid.GetWorldPosition(x, y) + quadSize * 0.5f] (without the brackets) but if I remove the * 0.5f from the end it makes it worse. This is exactly how it is in the video, though, so I don't know why it's different for me. It worked before I tried converting it into the tilemap visual object, so I don't understand why it's not working now. also, thanks for the quick reply. You're always good for that.
@GlyphicEnigma
@GlyphicEnigma Год назад
@@CodeMonkeyUnity Okay so if I set the cell size to 1 when I'm creating the tilemap, the gap disappears, but the visual is still half a cell width up and to the left of the cells I click on.
@MsEvanGreen
@MsEvanGreen Год назад
Hi @CodeMonkeyUnity! Can you please give some advice - how to get array of gridNode objects that you creating in test script? Or may be is exist different metod to get coordinates of all gridNode objects with isWalkable false value?
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
What part of the video are you referring to? The Grid class? That was made in the previous video unitycodemonkey.com/video.php?v=waEsGu--9P8
@MsEvanGreen
@MsEvanGreen Год назад
​@Code Monkey I reviewed the video and the solution is that Grid creating GridNodes is a 2D-array in final form C# is new for me and I never seen 2D-arrays before, but now its clear) Thank you!
@furiousd-gamedeveloper4672
@furiousd-gamedeveloper4672 4 года назад
First of all, Code Monkey, Thanks for these awesome tutorials! Now I'd like to ask for some help: how can we add collision to these tiles? So that a 2d character would be able to stand on them. I tried adding a MeshCollider to the TilemapVisual object, then setting it's sharedMesh to our mesh, but it didn't work. Tested with a rigidbody + box collider 2d. At least point me at the right direction, please!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
The official Unity Tilemap uses the Composite Collider component which lets you build a collider shape from various other shapes like BoxColliders. So in their implementation they add a BoxCollider to each tile which then is used by the Composite Collider.
@furiousd-gamedeveloper4672
@furiousd-gamedeveloper4672 4 года назад
@@CodeMonkeyUnity Thanks for the answer! I've looked into the Composite Collider and it seems to be a great solution! Looks like I need create BoxCollider2D's at the tile positions and it will all be handled by this thing. BUT I don't know if it's okay to have around a 1000 BoxCollider2D elements at the same time. It might have an impact on performance. (Talking about small tiles like in Duck Game, Terraria, Starbound, ...). It would probably be a good idea to create one BoxCollider2D for multiple tiles in a row as a way to optimize it.
@furiousd-gamedeveloper4672
@furiousd-gamedeveloper4672 4 года назад
I made it so that Unity generates all the BoxColliders when grid's loaded. Then I can just enable/disable them. Would need to change them for non-square shaped tiles though... This approach makes the game fly when you're setting regular square-shaped tiles. But it makes the game lag when it needs to load a big grid.
@DeveloperJake
@DeveloperJake 2 года назад
I've had this same question for 4 hours
@QuangNguyen-lf4lu
@QuangNguyen-lf4lu 11 месяцев назад
Thank you as for your tutorial. I have a question. How does this save load system work with assets? Like sprite, sound, prefab,... For example, I want to save and load sprite at each grid position, and when I save sprite, in the file it writes: "sprite":{"instanceID":29168} I am able to save and load normally. But I want to know if it's still the same when I build and run game in other devices? And does it apply to other assets as well?
@CodeMonkeyUnity
@CodeMonkeyUnity 11 месяцев назад
Don't do that, it will break when you make a build or just change something in the editor that causes the InstanceID to regenerate. Instead save something like an Enum, then in your code you know which Enum represents which Sprite Or simply ask yourself do you need to save the Sprite at all? Perhaps it's part of something else. For example in my upcoming game Dinky Guardians I don't save a Prefab reference for the Dinky objects, instead I just save the dinky save data in a save data list, then when loading I already know it's a Dinky so I spawn the Dinky prefab
@QuangNguyen-lf4lu
@QuangNguyen-lf4lu 11 месяцев назад
@@CodeMonkeyUnity thanks, I guess I will try a different approach. I wanted to load the sprite, then get the terrain reference from the sprite, since one terrain "Road" may have many different visuals, different sprites. I will try making enum for sprite to see if it works. Thanks for your advice.
@lisandromarina835
@lisandromarina835 8 месяцев назад
Hi Code Monkey! i want to do a PathFinder with Custom Tilemap, can i do that? did you cover it?
@CodeMonkeyUnity
@CodeMonkeyUnity 8 месяцев назад
Not sure what you mean by that, your pathfinding logic should be separate from whatever you use for visuals, I covered pathfinding here unitycodemonkey.com/video.php?v=alU04hvz6L4 Which you could then combine with this tilemap Or you can look at how I did it in my TBS game unitycodemonkey.com/video.php?v=QDr_pjzedv0
@user-vw9cv4ic1p
@user-vw9cv4ic1p Год назад
Hello sir, I have a question about the function at 8:36. My TilemapVisual only works(visible) in scene view, and its location is at the top right corner of the screen. I download the project file and it seems like my code is basically the same as the project file. No error in Console either. I wonder what could be the problem here.
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
Doesn't sound like a problem, just move your camera
@user-vw9cv4ic1p
@user-vw9cv4ic1p Год назад
@@CodeMonkeyUnity Thanks for your response, I fix the problem. I have another question. I wonder why use Mesh in a 2D game and why not just use sprite and spriteRenderer?
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
A SpriteRenderer is a mesh, it's a flat quad, it just has a different name. You can put your Scene view into Wireframe mode to see the SpriteRenderer mesh
@pepsipwns666
@pepsipwns666 2 года назад
With any grid above 100*100 my width is staying stuck at 100 and height increasing only it seems. The mesh starts to look all distorted... any idea? Is this something like max vertices in a single mesh? I would have to create multiple mesh' at this point?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
The mesh limit is 65k vertices so 100x100 should work with 40k vertices
@pepsipwns666
@pepsipwns666 2 года назад
​@@CodeMonkeyUnity 100x100 works fine, but above around 140~ the tiles start to look distorted/stretched/squished.... is this the point where I need to do chunking of 100*100 grids?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
@@pepsipwns666 140x140 requires 78k vertices which is above the 65k limit so yes at that point you need to handle multiple chunks
@walldoffstudios
@walldoffstudios 4 года назад
Do you have any tips on how to apply bool values to all tiles in Unity's built in TileMap? I need to be able to set a tile with a Vector3Int to false after placing an object on it and setting that same tile to true if i sell the object placed on it. i've tried implementing this tutorial into my game but i couldnt figure out how to adapt it to work with my other functions. Any help is appreciated, and love your videos btw keep up the good work! :)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
You mean store extra metadata in each Tilemap cell? I haven't used it much so not sure but maybe you can use tilemap.SetTile(); and make a custom class that extends TileBase
@walldoffstudios
@walldoffstudios 4 года назад
​@@CodeMonkeyUnity Thanks for putting me on the right track! Managed to find a solution for it! :)
@tstkenny630
@tstkenny630 Год назад
Could anyone share a working version of the .cs files or the project by a git repo? I am pretty sure that many visitors are unable to make it work after hours of researching... thank you!
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
There's a link in the description to download the project files
@tstkenny630
@tstkenny630 Год назад
@@CodeMonkeyUnity My bad. Thank you soooo much!
@user-cm6ux5si1x
@user-cm6ux5si1x Год назад
I LOVE YOU
@heinstain8438
@heinstain8438 5 месяцев назад
Hey CodeMonkey, I doubt you'll see this comment on a 4 year old video, but if you do, I'm, having trouble around the 8 minute mark. I've gone through this video and all your others several times, and I cant seem to figure out whats wrong. I'm not getting any errors, and all the data is changing correctly, however the mesh visual is not updating when clicked.
@CodeMonkeyUnity
@CodeMonkeyUnity 5 месяцев назад
Add some Debug.Log to see what your code is doing. Is the code testing for Input running? Is SetTilemapSprite(); being called? Does it have the correct world position? Is the event being fired and then updating the visual?
@heinstain8438
@heinstain8438 5 месяцев назад
Thanks for the reply! I actually realized that it was because I forgot to put "girdValueUV" in the "AddToMeshArrays" constructor at the end of "UpdateXMapVisual"@@CodeMonkeyUnity
@heinstain8438
@heinstain8438 5 месяцев назад
Thanks for the reply, turns out I forgot to swap "gridValueUV" into the "AddToMeshArrays" constructor@@CodeMonkeyUnity
@piobug
@piobug Год назад
Thanks!
@stressbuster5500
@stressbuster5500 2 года назад
I want to implement a system in my game where a player can share their level that they build in-game to others as you said at 24:40. How can I achieve this? If anyone reading this has any idea about it Could you Please share it
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
You have the save file stored, how you share that depends on what kind of server infrastructure you have.
@stressbuster5500
@stressbuster5500 2 года назад
@@CodeMonkeyUnity thanks for your reply. As an expert can u recommend what should I use in this particular situation (Just to share save files). I didnt find any useful information on internet.
@dumitruiordachi
@dumitruiordachi 3 года назад
It is possible to do in 3d?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Not sure what you mean by 3D, this is a flat mesh you can orient it in any way
@branidev
@branidev 4 года назад
can the begginner like me if i follow steps in this video make level editor in 2d platform game?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
The grid system is a bit complex so it depends on just how much of a beginner you are. If you're a beginner in Unity but not in C# you should be able to follow it. Check the playlist: ru-vid.com/group/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722
@verified_tinker1818
@verified_tinker1818 3 года назад
I'm late, but to the others wondering the same: use Unity's built-in Tilemap Editor. As Code Monkey said, you likely don't - and _shouldn't_ - need more, as a beginner. It's a bit like, "If you need to ask [the price], you can't afford it." If you need to ask whether you can make this, you probably can't.
@Nomarr
@Nomarr 4 года назад
OnChangeTile(TypeTile typeTile) => if(typeTile != TypeTile.None){ addCollider();} or something like that, :D
@Riodragon1
@Riodragon1 4 года назад
NICEEE!
@Ely_Dev
@Ely_Dev 4 года назад
I have one best system capacity to save Transform config and Scriptable configs
@luka6073
@luka6073 3 года назад
Someone has a clue about how to use this system with a Tileset? because this system is a little bit hard to use with 2d games with a side look :(
@charlesselrachski34
@charlesselrachski34 3 года назад
are you talking about horizontal scroller map? then put 3 grids side by side and slide them past the camera and when the left is off screen move the grid to the right side
@skriblz5887
@skriblz5887 4 года назад
Can i combine this with the a* pathfinding?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Sure, if they both use the same underlying grid then its very simple to make a tile for a rock and make it unwalkable on the pathfinding grid
@umarmohd3511
@umarmohd3511 4 года назад
@@CodeMonkeyUnity Should I directly set the walkability (this is a word?) of the Path Node in the method of changing the sprite of the tile (this I know how to do), or would it be more optimal to add the walkability method to the Trigger Grid Object Changed event (this I don't)?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
@@umarmohd3511 You should probably keep the Visual and Logic separate and have another script that listens to visual changes and applies path changes.
@MrJimmyAinsley
@MrJimmyAinsley 2 года назад
I added the MeshUtils and followed everything but somehow all I get are a few yellow lines that are drawn over my grid randomly, I can't get the color from the black red yellow green texture to be applied in the grid, it's all transparent with None/Ground, and then those weird yellow lines. Any idea what I'm missing?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
What part of your texture is yellow? Sounds like a UV issue, add some Debug.Log's to see what UV's you're using.
@tiger4092
@tiger4092 4 года назад
If anyone here hasn't heard of Rule Tiles (2D Extras) or Advanced Rule Tiles (asset store), you should learn about them because they make developer and player editing much easier. There's also lots of other tiles such as Animated and Random that are very useful.
@general_md
@general_md 3 года назад
How can I use it isometrically?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
If its just rotated then you can leave the grid as rectangular and just move the camera. Otherwise you just have to do some math
@general_md
@general_md 3 года назад
@@CodeMonkeyUnity the sprites are rotated (actually drawn isometrically )
@HomeBrewGeeks
@HomeBrewGeeks 3 года назад
@@CodeMonkeyUnity I'd like to second this question. I've been able to convert your grid class to handle isometric so far, tile picking is done, but the rendering is always bottom left to top right, instead of lowest y always on top. Any ideas? I asked in discord and CPU thought it was a uv problem, and I tried all his suggestions, nothing affects the way the mesh is drawn so far.
@JoBader
@JoBader 4 года назад
great!
@kaderkader1771
@kaderkader1771 4 года назад
vektor graphics for ui video please
@Mechanist
@Mechanist 3 года назад
With my tilemap, some of the tile textures are off by one pixel on certain x values like x = 5 when cellSize is 10f. It seems like you had the same problem at 16:34. How did you fix it?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
You mean the gaps? That's not being off by one pixel, it's just the automatic scaling of the texture. If the tile next to it is transparent that can happen. You can fix it by adding a tiny bit of padding on each tile texture.
@Mechanist
@Mechanist 3 года назад
@@CodeMonkeyUnity My textures where off by a pixel, I could see one pixel the previous texture in the atlas but only on certain columns. Im also using my own textures so that could be an issue but my current theory is a rounding error maybe.
@lawnslawn8082
@lawnslawn8082 2 года назад
I had the same problem. They were off by one pixel. The pixel count starts at 0, so the 64th pixel is pixel 63. Lower uv11Pixels.x by 1, e.g. 64 = 63, 128 = 127, 192 = 191 etc, etc.
@ritergart
@ritergart 4 года назад
Nice
@kaderkader1771
@kaderkader1771 4 года назад
vektör graphics video please
@marethos.8315
@marethos.8315 3 года назад
Hello CM! I was wondering if you could help me out. I am currently trying to do this Tutorial, but some things just dont want to work sadly. Following the tutorial step by step (Using your Grid system implemented in another video) i get an Error: "The non-generic type 'Grid' cannot be used with type arguments" This is spat out for multiple lines. Even if I copy your script from the UnityPackage provided for download (awesome btw!), it does not work. Trying to see if i have done something wrong i tried the "GameScene_Tilemap" which is in the tilemap assets folder where everything seems to be set up. Sadly the GameHandler and other Objects are missing Scripts. Since there is no README included i want to ask you if you know of a possible solution for this project. I really love the idea and would love to get it working. Keep up the great work CM!
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Do you have the Grid class with generics? It was made in this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8jrAWtI8RXg.html Based on the error it sounds like you're using the built-in Unity Grid class instead This video was made a long time ago so I don't remember what's in the package, you can download the project files for the video that I just released which also uses the tilemap ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-n-R-mg0Svlo.html
@FitDetailssw
@FitDetailssw 4 года назад
Hi
@Gytimaru
@Gytimaru Год назад
Hey CodeMonkey, I love your videos but sometimes you go a bit too fast and fix things without explaining and I think it is damaging for people like me who are trying to follow and are still relatively new to more advanced programming technics like lambda expression inside a constructor. For example, at 3:42 you change the constructor to use the TilemapObject but in the Func part, you write: (Grid g, int x, int y)=>new TilemapObject(grid, x, y)); instead of: (Grid g, int x, int y)=>new TilemapObject(g, x, y)); Notice the new TilemapObject argument, you only write "grid" in the video but you never mention or even show that you changed it to "g". I think it would be useful for everyone if you would show these things and explain a bit about common problems that can happen. Again, I love your videos and I hope you will appreciate my constructive criticism.
@KarateRai
@KarateRai 2 года назад
Why o why would you have so many classes inside of other classes? Its bad practise to have a class within a class
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
You should have as many classes as you need and no more. If something makes sense to be in its own class then it should be in its own class. Definitely don't put everything in one giant megaclass just because you want to avoid making more classes.
@krzysztofparadowski624
@krzysztofparadowski624 4 года назад
Oh man so many nice features and I cant get it done for hexes whyyy :-(
@benshaw9951
@benshaw9951 3 года назад
Dude slow down, wtf
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Feel free to pause as much as you need, remember this is your learning journey, you're not competing with anyone but yourself. So take your time and just focus on learning
@brianjensen2532
@brianjensen2532 3 года назад
I don't like the packaging of the Util class with everything in every project. Tons of useless junk in packages. Also the Utils class is just a nice way to hide the fact Camera.main is used everywhere. This is not code you should use. Nor should you hide it in such a manner. Shame on you.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Feel free to write your own Utilities or just write the specific function you need, there's nothing special about my particular utilities, it's just so I don't write the same code over and over again. Shame on me for giving you free education? Ok then
@highimpact1
@highimpact1 3 года назад
@@CodeMonkeyUnity I think packing shortcut functions in a class is a good way to save time and typing. Bravo!
@mamalademand
@mamalademand Год назад
I'm having some trouble at 23:50. When i save the scripts i get this error code: "Assets\Scripts\Tilemap.cs(25,23): error CS7036: There is no argument given that corresponds to the required formal parameter 'grid' of 'TilemapVisual.SetGrid(Tilemap, Grid)'" The problem seems to be with the "SetGrid" but i can't figure out how to fix it. " public void SetTilemapVisual(TilemapVisual tilemapVisual) { TilemapVisual.SetGrid(grid); } " The SetGrid function in TilemapVisual is: " public void SetGrid(Tilemap tilemap, Grid grid) { this.grid = grid; UpdateHeatMapVisual(); grid.OnGridObjectChanged += Grid_OnGridValueChanged; tilemap.OnLoaded += Tilemap_OnLoaded; } " Any ideas as to how i fix it?
@CodeMonkeyUnity
@CodeMonkeyUnity Год назад
Your SetGrid() function expects two arguments, a Tilemap and a Grid but you're only passing in a single grid parameter
@mamalademand
@mamalademand Год назад
@@CodeMonkeyUnity Thank you very much for your fast response. When i change it to: " public void SetTilemapVisual(TilemapVisual tilemapVisual) { TilemapVisual.SetGrid(Tilemap, Grid); } " I instead get the CS0119 error: "Tilemap"/"Grid
Далее
Steam EXPERT teaches you Game Marketing for SUCCESS!
52:22
TILEMAPS in Unity
13:45
Просмотров 1,8 млн
NVIDIA Needs to STOP - RTX 3050 & Misleading Branding
11:35
It's time for change, it's time for Linux.
10:53
Просмотров 370 тыс.
Why Nintendo Devs Hate Working With Miyamoto
16:02
Просмотров 36 тыс.
Simple Drag Drop (Unity Tutorial for Beginners)
10:31
Просмотров 323 тыс.
What are Events? (C# Basics)
15:05
Просмотров 387 тыс.