Is it possible to attach scripts to 2D tiles?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PixelWizzard
:warning: Old Version Published before Godot 3 was released.

I tried to include sprites with attached scripts into a tilemap, but these scripts don’t seem to be executed when using these tiles. Could there be any way, to get this to work, or is there a reason behind this?

:bust_in_silhouette: Reply From: neikeq

It’s not possible, you cannot have a script for each tile. This is a quote from reduz explaining the limitation of TileMap in favor of performance:

more stuff could be eventually added, but in truth the idea is that you should combine the tilemap with instanced objects, not use one or the other.
Tilemap is designed to draw large amount of quads quickly, so adding more flexibility would beat the purpose. What is the problem of combining both?

As he explains, if you want more advanced behaviour, you can use other nodes for that task.

Well, thanks for that. This is actually, what I’m currently doing. But I was curious, if there is a more simple or elegant way.

PixelWizzard | 2016-03-06 19:24


I am sorry to re-open this thread, even if I found it useful to understand the limitations of TileMap node.
However, being new to Godot, I am running into the same problem as PixelWizzard and I can’t find a proper way to solve this problem.

For now I am using scenes as tiles (with script attached to it), but I don’t think it is the way to go when there are hundreds/thousands of tiles involved.

Does anyone has an idea on the best way to do it ?

Many thanks in advance :slight_smile:

ocre | 2016-10-10 16:02