I need to add script components and colliders etc to the tiles in my tile pallet. How do I do this?
Does no one know anything about this? It seems like it is a pretty fundamental feature, yet I can not find any documentation explaining how to do it.
You use TileBase as your base class to create a custom Tile as a ScriptableObject asset in your project folder.
You override those four public methods including StartUp and RefreshTile to setup your tile’s behavior during gameplay. StartUp provides the GameObject instantiated for your tile.
Almost everything in the new Tilemap section of the docs has a scripting example, so use those as your foundation.
Thanks, I will take a look at that.
I looked at the link you provided but didn’t get a lot out of it. I would like to add tags to my tiles. For example, cave, forest, desert, shallow water, deep water, etc… Do I need to do this or do I use something like: public TileBase cave, etc …
or something like that and script the behaviors of each TileBase rather than tag them?
I should be more specific. I have created multiple palettes under one tile map. I want each palette to have its own components and tags. The only thing that I can seem to do is create a different tile map in order to add components; however, I don’t seem to be able to add to individual tiles regardless, for the 2D collider component gets added to the entire tile map rather than the individual tiles within it.
I was a bit confused but I think I figured it out.
In order to apply colliders, create separate tilemaps. Add a TileMap2d collider to the desired tilemap. From what I can tell, one must be careful which tilemap is selected because if a wall tile is highlighted and you switch over to the ground tiles palette, it will still apply a potentially unwanted collider. (I’m doing a top down so my ground tiles don’t require collision except the sand, deep grass, and shallow water, which is an IsTrigger to apply speed reduction and audio).
Hopefully someone will find this helpful.
How do you use the custom Tile as a ScriptableObject asset in your project folder? i.e. what are the steps involved in doing this? I am really struggling to find anything about how to perform the first step, Custom Tile isn’t an option I can see and tile objects don’t seem to allow you to attach any custom scripts to them
You can include the CreateAssetMenu attribute just before your custom Tile class. Then a menu item for your custom class will be visible in the Create menu just above “Folder”.
Example:
using UnityEngine.Tilemaps;
[CreateAssetMenu(fileName = “new customTile”, menuName = “customTile”)]
public class customTile : TileBase
{
}
Good luck!
How do I make a tile that I can add SpriteRenderer, Animator, RigidBody2D, BoxCollider2D and other scripts to?
I don’t want to create a prefab and I don’t want to put these components to a whole TileMap.
You cannot, a tile isn’t a GameObject.
Thank you.