How to store unique data in each tile (Unity 2D Tilemap tutorial)

Learn to create a map that can represent stuff like heat, oxygen or stink. I chose the latter one as an example.... The underlying system here is a script that stores the data based on a tilemap, which we also use to visualize it.
Get the full project here (free) : github.com/ShackMan2000/Tutor...
To see the system in action we will create a skunk that spreads stink which will be visible with Unitys Tilemap. A pig will roam and read that data to navigate.
Check out my newest game Idle Potato Power. It's a fun and relaxing game about exploring Potato Power in all it's multidimensional weirdness.
play.google.com/store/apps/de...
github.com/ShackMan2000
Discord: / discord

Пікірлер: 32

  • @FlipYourLearning
    @FlipYourLearning2 жыл бұрын

    This was amazingly useful. I had been trying to implement a similar system for days and honestly wasn't expecting to find a video showing how to do such a niche thing (I want to use it for immune cells and bacteria leaving trails of molecules as they move. My best bet at first was to look for temperature maps and heat transfer simulation videos, but it didn't work well. Suddenly I saw your miniature mentioning stink, and I realized that it was exactly what I needed, and the video did not disappoint). Thanks a lot.

  • @krissichan3127
    @krissichan31273 жыл бұрын

    Beautiful my man, very good.

  • @pavelholub6275
    @pavelholub62752 жыл бұрын

    Thanks for this! Now i am able to make humidity, organic matter and heat maps :)

  • @titushenson8227
    @titushenson82272 жыл бұрын

    Took my like an hour to find this just what I was looking for

  • @bm3410
    @bm34102 жыл бұрын

    "adjust it for the x and y, and add some stink" *thumbs up*

  • @gavin_is_gavin6292
    @gavin_is_gavin62922 жыл бұрын

    oh man, thanks for the info about the color lock. I had no idea why my code wasn't working!

  • @manyfailsonewin4352
    @manyfailsonewin4352 Жыл бұрын

    This and the other video about tiles has been extremely helpful. I shot myself in the foot by accidentally making the darker stink tile on alpha 0 and kept wondering why my second and third clicks were making things fade lol. This will help me immensely in creating a tiled game with water and other flowing types of materials (I hope!). So far so good!

  • @ShackMan

    @ShackMan

    Жыл бұрын

    That happens to everyone, Unity sets the alpha of new colors to 0. Must have wasted about a million hours of dev time in total...cool user name btw, great attitude :-)

  • @manyfailsonewin4352

    @manyfailsonewin4352

    Жыл бұрын

    @@ShackMan ahh that makes me feel a little better. i was wondering how i managed to goof that up. thanks!

  • @HazebertM
    @HazebertM2 жыл бұрын

    Hi, great tutorial! I've been following along but, every time I run the first test, it never adds color. When I turn the alpha back up, clicking the just removes the tile. I've followed the code completely as shown in the video. Any idea of what I might be doing wrong? Thanks!

  • @killhour
    @killhour2 жыл бұрын

    One thing that would be good to add is the ability to use the tilemap to create an initial state that the game can start with instead of having everything initialized to 0 - think cellular automata.

  • @322ss
    @322ss2 жыл бұрын

    Pretty nice stuff! I've done something similar, but I've never considered using updating tiles in runtime scenarios. Have you done any profiling/testing, how many updating tiles will bog your computer down?

  • @ShackMan

    @ShackMan

    2 жыл бұрын

    I didn't do actual profiling, just stress testing and it could handle a lot! I've found tilemaps to be quite performant in general, and my method here doesn't do that much work. And it could of course be optimized when you know what exactly your game needs.

  • @obygdengaming
    @obygdengaming3 жыл бұрын

    Thanks for the tutorials! Quick question, how would I go about iterating through all the tiles in the tilemap, finding all tiles with a certain Int value set in their TileData, and add them to a list? I am new to Tilemaps and Scriptable objects, and get a bit confused with all the new terms lol

  • @ShackMan

    @ShackMan

    3 жыл бұрын

    Use Tilemap.origin to get the lower left corner and Tilemap.origin + Tilemap.size for the top right corner. Those are vectors giving you the positions. That way you can loop through all the tiles. Checking whether a tile has a certain stink value is then a simple if statement. In this video I only added the stinking tiles to the dictionary. So you could loop through all positions in the tilemap and check if the stinkingTiles dictionary has that position as a key, if so, get the value of that key to check the stink value.

  • @obygdengaming

    @obygdengaming

    3 жыл бұрын

    @@ShackMan Ahhh I figured it out! Thanks so much! I'm gonna post my solution here if anybody else needs it: //Get the map area BoundsInt bounds = map.cellBounds; // Get all tiles in map area TileBase[] allTiles = map.GetTilesBlock(bounds); //Iterate through all tiles foreach(TileBase tile in allTiles){ //Make sure there is a tile at position and check a bool from the TileData if(tile != null){ if(dataFromTiles[tile].switchTile == true){ Debug.Log("Found Switchable Block"); // adds it to a list based on a TileData int value if(dataFromTiles[tile].switchNumber == 0){ switchableTiles0.Add((dataFromTiles[tile])); } } } }

  • @PeterMilko
    @PeterMilko3 жыл бұрын

    cool

  • @AlexFSTR
    @AlexFSTR2 жыл бұрын

    Hello, I have a tile animation, but I would like to place it in a tilemap, I would like to do all this in code. But tilemap has only one function which is SetTile() which asks me for a TileBase, so the question, how can I convert my TileAnimatorData to TileBase?

  • @ShackMan

    @ShackMan

    2 жыл бұрын

    You could write a script that just swaps the sprite every 0.x seconds with SetTile, looping through a list of your sprites. Sounds incredibly bad for performance, but I think it's always worth trying it out and see what happens. There are of course animated tiles that you can create in the inspector, but I've never tried out how to set the sprites through script. docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/manual/AnimatedTile.html

  • @sjs_ujs
    @sjs_ujs Жыл бұрын

    very good ,tsk

  • @TengizAdamashvili
    @TengizAdamashvili2 жыл бұрын

    Question. How would you store unique data in EVERY tile? I can iterate over each tile and that gives me row and col values, which do not correspond to grid_position values. I tried getting a world bounding box position, so I can find each tile by iterating coordinates but the tilemap bounding box is super janky and simply wrong and unreliable. Please advice

  • @ShackMan

    @ShackMan

    2 жыл бұрын

    Not sure, what what you mean... the row and col value should exactly correspond to a grid position, by which you can get the world position (the center of the tile).

  • @ausername4meplease
    @ausername4meplease Жыл бұрын

    Can this system be used in a farming game where you dig, water and plant things in tiles? What about performance? Thank you for a great tutorial!

  • @ShackMan

    @ShackMan

    Жыл бұрын

    Sure. Performance depends on the size of the tilemap and how intensively you process it. My advice in general is to just try it out, once you have the core mechanics down, do a stress test where you increase the size/processing by 100x or 1000x and see what happens.

  • @remilaurent2055
    @remilaurent205510 ай бұрын

    Is it possible to change the sprite of tile when it's clicked ?

  • @ShackMan

    @ShackMan

    10 ай бұрын

    Yes, I have another video with how to change tiles at runtime, you can swap the tile at runtime through code.

  • @alexeyprosin6343
    @alexeyprosin6343 Жыл бұрын

    Dictionary? Ouch... That was painful.

  • @quadroninja2708

    @quadroninja2708

    16 күн бұрын

    idk, log2(n) seems like an okay efficiency

  • @rebelcrusader9973
    @rebelcrusader99732 жыл бұрын

    Dude, it's all fine and good, but why do you add so many empty lines when coding? I have to constantly go back because your previous code gets constantly hidden by the absurd amount of empty lines you add for no reason.

  • @manyfailsonewin4352

    @manyfailsonewin4352

    Жыл бұрын

    some reason some ppl prefer to put their { on same line and some don't, i would guess. just little things that makes it easier for ppl to read their own code.