The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

hello. my question is simple. can i attach a script to a tile in a tileset? i really need it because for my game each tile got some properties that i can include them in the script for tile. note that i need to access to these properties from other nodes.

in Engine by (84 points)

i need the answer too!
i googled, it seems no one know how to do it...

1 Answer

+1 vote

It is not recommended to do so. However, you can easily check for the type of tile via the tileMap node:

tile_pos = world_to_map(pos) #Maybe you don't even need this
tile_type = get_cell(tile_pos.x, tile_pos.y)

You can either get the position of the needed tile by iteration or by your mouse cursor or character position. The get_cell(...) method returns the Tile ID as an integer number. Each tile has a different ID.

Hope this helped!

by (37 points)

if i can't add scripts, than i must not use tilemaps! is there a way to see the name of tile? intead of its id?

I use the following inside TileMap:

func get_tile_name(location: Vector2) -> String:
    var position := world_to_map(location)
    var tile := get_cellv(position)
    if tile == -1:
        return ""

    return tile_set.tile_get_name(tile)

and a shorthand for finding the id:

func get_tile_id(name: String) -> int:
    return tile_set.find_tile_by_name(name)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.