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

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 33

  • @ForestDenison
    @ForestDenison Місяць тому

    Thanks! Working on a project that generates a world using Perlin Noise and I wanted to add some extra information to each tile regarding the town that occupies that space. Very useful!

  • @FlipYourLearning
    @FlipYourLearning 2 роки тому +6

    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.

  • @gavin_is_gavin6292
    @gavin_is_gavin6292 2 роки тому

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

  • @pavelholub6275
    @pavelholub6275 2 роки тому

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

  • @manyfailsonewin4352
    @manyfailsonewin4352 2 роки тому

    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  2 роки тому +1

      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 2 роки тому

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

  • @titushenson8227
    @titushenson8227 2 роки тому

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

  • @bm3410
    @bm3410 2 роки тому

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

  • @krissichan3127
    @krissichan3127 4 роки тому +1

    Beautiful my man, very good.

  • @322ss
    @322ss 3 роки тому +1

    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  3 роки тому +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
    @obygdengaming 4 роки тому +2

    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  4 роки тому +6

      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 4 роки тому +2

      @@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]));
      }
      }
      }
      }

  • @AlexFSTR
    @AlexFSTR 2 роки тому

    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

  • @ausername4meplease
    @ausername4meplease 2 роки тому

    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  2 роки тому +1

      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.

  • @HazebertM
    @HazebertM 3 роки тому

    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!

  • @TengizAdamashvili
    @TengizAdamashvili 2 роки тому

    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).

  • @PeterMilko
    @PeterMilko 4 роки тому

    cool

  • @remilaurent2055
    @remilaurent2055 Рік тому

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

    • @ShackMan
      @ShackMan  Рік тому

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

  • @sjs_ujs
    @sjs_ujs Рік тому

    very good ,tsk

  • @alexey6343-x0
    @alexey6343-x0 2 роки тому

    Dictionary? Ouch... That was painful.

    • @quadroninja2708
      @quadroninja2708 5 місяців тому

      idk, log2(n) seems like an okay efficiency

  • @rebelcrusader9973
    @rebelcrusader9973 3 роки тому +3

    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 2 роки тому +1

      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.