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

  Рет қаралды 20,418

Shack Man

Shack Man

Күн бұрын

Пікірлер: 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 жыл бұрын
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.
@bm3410
@bm3410 2 жыл бұрын
"adjust it for the x and y, and add some stink" *thumbs up*
@titushenson8227
@titushenson8227 2 жыл бұрын
Took my like an hour to find this just what I was looking for
@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 жыл бұрын
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!
@krissichan3127
@krissichan3127 4 жыл бұрын
Beautiful my man, very good.
@322ss
@322ss 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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
@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).
@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!
@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
@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.
@PeterMilko
@PeterMilko 4 жыл бұрын
cool
@sjs_ujs
@sjs_ujs Жыл бұрын
very good ,tsk
@alexey6343-x0
@alexey6343-x0 2 жыл бұрын
Dictionary? Ouch... That was painful.
@quadroninja2708
@quadroninja2708 4 ай бұрын
idk, log2(n) seems like an okay efficiency
@rebelcrusader9973
@rebelcrusader9973 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 жыл бұрын
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.
Are Unity's Tile Features Good Enough to Make Real Games?
36:20
AdamCYounis
Рет қаралды 130 М.
Человек паук уже не тот
00:32
Miracle
Рет қаралды 4,3 МЛН
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 127 МЛН
Pathfinding - Understanding A* (A star)
12:52
Tarodev
Рет қаралды 135 М.
The Solution to ALL of Your Rule Tile Problems!
12:12
Vinark117
Рет қаралды 8 М.
⚡ Всё про события в Unity 3D
21:38
Emerald Powder
Рет қаралды 108 М.
Tile Map auto generation in Unity - TUTORIAL
32:38
Daniel Hofmann
Рет қаралды 115 М.
Flexible LOOT SYSTEM in Unity with Random Drop Rates
13:24
Watch This Before You Make Your First Game!
14:35
Thomas Brush
Рет қаралды 319 М.
How to change tiles at runtime in Unity (Burn your tilemap!)
11:39
Edit, Save And Load Unity Tilemaps At Runtime!
17:04
Vinark117
Рет қаралды 13 М.
Key Rebinding with Unity's New Input System and Generated C# Code
51:03
One Wheel Studio
Рет қаралды 22 М.
Escaping Unity Animator HELL
18:18
Lost Relic Games
Рет қаралды 515 М.