Unity: Tilemap Events

October 5, 2018 Package, Unity

As you know, Unity has released the Tilemap feature in the 2017.2 Editor release. This is an awesome feature that permits you to create cool maps for your 2D games.
Unfortunately, this feature lacks the Events management capability. That’s why we brought to you this package!

Let’s see how it does work:

Create a tilemap

The first thing to do is, of course, create your awesome map.
For this tutorial, I’ve used the 2D Hand Painted – Grassland Tileset available on the store at this link.

Download and import the package

Go to the Github repository at https://github.com/NTWalkers/unitytilemapevents and download the latest package version found under the Releases folder.

To import the package right-click on the Assets folder under the Project folder and select Import Package -> Custom Package… and then select the downloaded package.

Add your Events Tilemap

The next step is to add yout Events Tilemap to the project.

To do that right click on the Hierarchy and select 2D Object -> Event Tilemap.

An event tilemap it’s still a tilemap so you can draw tiles on it.
Those tiles will represent the actual event.
I suggest putting this tilemap on the higher Sorting Layer. Do not worry, at runtime the events till will automatically hide. This will permit you to see the events on editing.

In my example, I added an event on the cave entry as you can see from the image above. If you need an image that represents an event you can use the one that I used. Here it is:

Let’s see how the component looks like:

The array of tiles contains all the event tiles drawn.
Following the meaning of tiles parameters :

  1. Name: The name of the event.
  2. Interactable Tag: The tag that the object needs to have to interact with that event.
  3. Trigger: The type of trigger. Actually supported values are On Enter Collision and On Interaction.
  4. On Event(): The method or the stack of methods to be called when the event is fired.

Fire the event

Firing the event is pretty simple:

You just need to move your player (or the designated object) into the tile and the event will fire.

Of course your object needs a RigidBody2D and a Collider2D (Box, Circle, Polygon etc etc are all fine).