Search Unity

Tile Pallet. How do I add components to tiles?

Discussion in '2D' started by coolblue2000, Oct 16, 2017.

  1. coolblue2000

    coolblue2000

    Joined:
    May 7, 2015
    Posts:
    24
    I need to add script components and colliders etc to the tiles in my tile pallet. How do I do this?
     
  2. coolblue2000

    coolblue2000

    Joined:
    May 7, 2015
    Posts:
    24
    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.
     
    lfitzy95 likes this.
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    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.

    https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles.html
     
    Last edited: Oct 18, 2017
    Copostair, Rallix and coolblue2000 like this.
  4. coolblue2000

    coolblue2000

    Joined:
    May 7, 2015
    Posts:
    24
    Thanks, I will take a look at that.
     
    LiterallyJeff likes this.
  5. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    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?
     
  6. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    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.
     
  7. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    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. :D
     
    DungDajHjep likes this.
  8. lfitzy95

    lfitzy95

    Joined:
    Dec 29, 2021
    Posts:
    1
    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
    upload_2021-12-29_10-59-10.png
     
  9. Niklas_Elling

    Niklas_Elling

    Joined:
    Apr 4, 2017
    Posts:
    1
    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!
     
  10. IgorArnaut

    IgorArnaut

    Joined:
    Nov 15, 2021
    Posts:
    39
    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.
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    You cannot, a tile isn't a GameObject.
     
  12. IgorArnaut

    IgorArnaut

    Joined:
    Nov 15, 2021
    Posts:
    39
    Thank you.