Index · Object → RefCounted → Resource → TileSet

TileSet

Tile library for tilemaps.

Class Description

A TileSet is a library of tiles for a TileMapLayer. A TileSet handles a list of TileSetSource, each of them storing a set of tiles.

Tiles can either be from a TileSetAtlasSource, which renders tiles out of a texture with support for physics, navigation, etc., or from a TileSetScenesCollectionSource, which exposes scene-based tiles.

Tiles are referenced by using three IDs: their source ID, their atlas coordinates ID, and their alternative tile ID.

A TileSet can be configured so that its tiles expose more or fewer properties. To do so, the TileSet resources use property layers, which you can add or remove depending on your needs.

For example, adding a physics layer allows giving collision shapes to your tiles. Each layer has dedicated properties (physics layer and mask), so you may add several TileSet physics layers for each type of collision you need.

See the functions to add new layers for more information.

Properties

var tile_layout: TileSet.TileLayout = 0

For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), changes the way tiles are indexed in the TileMapLayer grid.

var tile_offset_axis: TileSet.TileOffsetAxis = 0

For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), determines the offset axis.

var tile_shape: TileSet.TileShape = 0

The tile shape.

var tile_size: Vector2i = Vector2i(16, 16)

The tile size, in pixels. For all tile shapes, this size corresponds to the encompassing rectangle of the tile shape. This is thus the minimal cell size required in an atlas.

var uv_clipping: bool = false

Enables/Disable uv clipping when rendering the tiles.

Inherited from Resource (4)

Methods

func add_custom_data_layer(to_position: int = -1) -> void

Adds a custom data layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Custom data layers allow assigning custom properties to atlas tiles.

func add_navigation_layer(to_position: int = -1) -> void

Adds a navigation layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Navigation layers allow assigning a navigable area to atlas tiles.

func add_occlusion_layer(to_position: int = -1) -> void

Adds an occlusion layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Occlusion layers allow assigning occlusion polygons to atlas tiles.

func add_pattern(pattern: TileMapPattern, index: int = -1) -> int

Adds a TileMapPattern to be stored in the TileSet resource. If provided, insert it at the given index.

func add_physics_layer(to_position: int = -1) -> void

Adds a physics layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Physics layers allow assigning collision polygons to atlas tiles.

func add_source(source: TileSetSource, atlas_source_id_override: int = -1) -> int

Adds a TileSetSource to the TileSet. If atlas_source_id_override is not -1, also set its source ID. Otherwise, a unique identifier is automatically generated.

The function returns the added source ID or -1 if the source could not be added.

Warning: A source cannot belong to two TileSets at the same time. If the added source was attached to another TileSet, it will be removed from that one.

func add_terrain(terrain_set: int, to_position: int = -1) -> void

Adds a new terrain to the given terrain set terrain_set at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

func add_terrain_set(to_position: int = -1) -> void

Adds a new terrain set at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

func cleanup_invalid_tile_proxies() -> void

Clears tile proxies pointing to invalid tiles.

func clear_terrains(terrain_set: int) -> void

Clears all terrain properties for the given terrain set.

func clear_tile_proxies() -> void

Clears all tile proxies.

func get_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) -> Array

Returns the alternative-level proxy for the given identifiers. The returned array contains the three proxie's target identifiers (source ID, atlas coords ID and alternative tile ID).

If the TileSet has no proxy for the given identifiers, returns an empty Array.

func get_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) -> Array

Returns the coordinate-level proxy for the given identifiers. The returned array contains the two target identifiers of the proxy (source ID and atlas coordinates ID).

If the TileSet has no proxy for the given identifiers, returns an empty Array.

func get_custom_data_layer_by_name(layer_name: String) -> int

Returns the index of the custom data layer identified by the given name.

func get_custom_data_layer_name(layer_index: int) -> String

Returns the name of the custom data layer identified by the given index.

func get_custom_data_layer_type(layer_index: int) -> Variant.Type

Returns the type of the custom data layer identified by the given index.

func get_custom_data_layers_count() -> int

Returns the custom data layers count.

func get_navigation_layer_layer_value(layer_index: int, layer_number: int) -> bool

Returns whether or not the specified navigation layer of the TileSet navigation data layer identified by the given layer_index is enabled, given a navigation_layers layer_number between 1 and 32.

func get_navigation_layer_layers(layer_index: int) -> int

Returns the navigation layers (as in the Navigation server) of the given TileSet navigation layer.

func get_navigation_layers_count() -> int

Returns the navigation layers count.

func get_next_source_id() -> int

Returns a new unused source ID. This generated ID is the same that a call to add_source() would return.

func get_occlusion_layer_light_mask(layer_index: int) -> int

Returns the light mask of the occlusion layer.

func get_occlusion_layer_sdf_collision(layer_index: int) -> bool

Returns if the occluders from this layer use sdf_collision.

func get_occlusion_layers_count() -> int

Returns the occlusion layers count.

func get_pattern(index: int = -1) -> TileMapPattern

Returns the TileMapPattern at the given index.

func get_patterns_count() -> int

Returns the number of TileMapPattern this tile set handles.

func get_physics_layer_collision_layer(layer_index: int) -> int

Returns the collision layer (as in the physics server) bodies on the given TileSet's physics layer are in.

func get_physics_layer_collision_mask(layer_index: int) -> int

Returns the collision mask of bodies on the given TileSet's physics layer.

func get_physics_layer_collision_priority(layer_index: int) -> float

Returns the collision priority of bodies on the given TileSet's physics layer.

func get_physics_layer_physics_material(layer_index: int) -> PhysicsMaterial

Returns the physics material of bodies on the given TileSet's physics layer.

func get_physics_layers_count() -> int

Returns the physics layers count.

func get_source(source_id: int) -> TileSetSource

Returns the TileSetSource with ID source_id.

func get_source_count() -> int

Returns the number of TileSetSource in this TileSet.

func get_source_id(index: int) -> int

Returns the source ID for source with index index.

func get_source_level_tile_proxy(source_from: int) -> int

Returns the source-level proxy for the given source identifier.

If the TileSet has no proxy for the given identifier, returns -1.

func get_terrain_color(terrain_set: int, terrain_index: int) -> Color

Returns a terrain's color.

func get_terrain_name(terrain_set: int, terrain_index: int) -> String

Returns a terrain's name.

func get_terrain_set_mode(terrain_set: int) -> TileSet.TerrainMode

Returns a terrain set mode.

func get_terrain_sets_count() -> int

Returns the terrain sets count.

func get_terrains_count(terrain_set: int) -> int

Returns the number of terrains in the given terrain set.

func has_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) -> bool

Returns if there is an alternative-level proxy for the given identifiers.

func has_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) -> bool

Returns if there is a coodinates-level proxy for the given identifiers.

func has_custom_data_layer_by_name(layer_name: String) -> bool

Returns if there is a custom data layer named layer_name.

func has_source(source_id: int) -> bool

Returns if this TileSet has a source for the given source ID.

func has_source_level_tile_proxy(source_from: int) -> bool

Returns if there is a source-level proxy for the given source ID.

func map_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) -> Array

According to the configured proxies, maps the provided identifiers to a new set of identifiers. The source ID, atlas coordinates ID and alternative tile ID are returned as a 3 elements Array.

This function first look for matching alternative-level proxies, then coordinates-level proxies, then source-level proxies.

If no proxy corresponding to provided identifiers are found, returns the same values the ones used as arguments.

func move_custom_data_layer(layer_index: int, to_position: int) -> void

Moves the custom data layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

func move_navigation_layer(layer_index: int, to_position: int) -> void

Moves the navigation layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

func move_occlusion_layer(layer_index: int, to_position: int) -> void

Moves the occlusion layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

func move_physics_layer(layer_index: int, to_position: int) -> void

Moves the physics layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

func move_terrain(terrain_set: int, terrain_index: int, to_position: int) -> void

Moves the terrain at index terrain_index for terrain set terrain_set to the given position to_position in the array. Also updates the atlas tiles accordingly.

func move_terrain_set(terrain_set: int, to_position: int) -> void

Moves the terrain set at index terrain_set to the given position to_position in the array. Also updates the atlas tiles accordingly.

func remove_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) -> void

Removes an alternative-level proxy for the given identifiers.

func remove_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) -> void

Removes a coordinates-level proxy for the given identifiers.

func remove_custom_data_layer(layer_index: int) -> void

Removes the custom data layer at index layer_index. Also updates the atlas tiles accordingly.

func remove_navigation_layer(layer_index: int) -> void

Removes the navigation layer at index layer_index. Also updates the atlas tiles accordingly.

func remove_occlusion_layer(layer_index: int) -> void

Removes the occlusion layer at index layer_index. Also updates the atlas tiles accordingly.

func remove_pattern(index: int) -> void

Remove the TileMapPattern at the given index.

func remove_physics_layer(layer_index: int) -> void

Removes the physics layer at index layer_index. Also updates the atlas tiles accordingly.

func remove_source(source_id: int) -> void

Removes the source with the given source ID.

func remove_source_level_tile_proxy(source_from: int) -> void

Removes a source-level tile proxy.

func remove_terrain(terrain_set: int, terrain_index: int) -> void

Removes the terrain at index terrain_index in the given terrain set terrain_set. Also updates the atlas tiles accordingly.

func remove_terrain_set(terrain_set: int) -> void

Removes the terrain set at index terrain_set. Also updates the atlas tiles accordingly.

func set_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int, source_to: int, coords_to: Vector2i, alternative_to: int) -> void

Create an alternative-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers.

Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.

func set_coords_level_tile_proxy(source_from: int, coords_from: Vector2i, source_to: int, coords_to: Vector2i) -> void

Creates a coordinates-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers. The alternative tile ID is kept the same when using coordinates-level proxies.

Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.

func set_custom_data_layer_name(layer_index: int, layer_name: String) -> void

Sets the name of the custom data layer identified by the given index. Names are identifiers of the layer therefore if the name is already taken it will fail and raise an error.

func set_custom_data_layer_type(layer_index: int, layer_type: Variant.Type) -> void

Sets the type of the custom data layer identified by the given index.

func set_navigation_layer_layer_value(layer_index: int, layer_number: int, value: bool) -> void

Based on value, enables or disables the specified navigation layer of the TileSet navigation data layer identified by the given layer_index, given a navigation_layers layer_number between 1 and 32.

func set_navigation_layer_layers(layer_index: int, layers: int) -> void

Sets the navigation layers (as in the navigation server) for navigation regions in the given TileSet navigation layer.

func set_occlusion_layer_light_mask(layer_index: int, light_mask: int) -> void

Sets the occlusion layer (as in the rendering server) for occluders in the given TileSet occlusion layer.

func set_occlusion_layer_sdf_collision(layer_index: int, sdf_collision: bool) -> void

Enables or disables SDF collision for occluders in the given TileSet occlusion layer.

func set_physics_layer_collision_layer(layer_index: int, layer: int) -> void

Sets the collision layer (as in the physics server) for bodies in the given TileSet physics layer.

func set_physics_layer_collision_mask(layer_index: int, mask: int) -> void

Sets the collision mask for bodies in the given TileSet physics layer.

func set_physics_layer_collision_priority(layer_index: int, priority: float) -> void

Sets the collision priority for bodies in the given TileSet physics layer.

func set_physics_layer_physics_material(layer_index: int, physics_material: PhysicsMaterial) -> void

Sets the physics material for bodies in the given TileSet physics layer.

func set_source_id(source_id: int, new_source_id: int) -> void

Changes a source's ID.

func set_source_level_tile_proxy(source_from: int, source_to: int) -> void

Creates a source-level proxy for the given source ID. A proxy will map set of tile identifiers to another set of identifiers. Both the atlas coordinates ID and the alternative tile ID are kept the same when using source-level proxies.

Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.

func set_terrain_color(terrain_set: int, terrain_index: int, color: Color) -> void

Sets a terrain's color. This color is used for identifying the different terrains in the TileSet editor.

func set_terrain_name(terrain_set: int, terrain_index: int, name: String) -> void

Sets a terrain's name.

func set_terrain_set_mode(terrain_set: int, mode: TileSet.TerrainMode) -> void

Sets a terrain mode. Each mode determines which bits of a tile shape is used to match the neighboring tiles' terrains.

Inherited from Resource (18)
func _get_rid() -> RID
func _reset_state() -> void
func _set_path_cache(path: String) -> void
func _setup_local_to_scene() -> void
func copy_from_resource(resource: Resource) -> Error
func duplicate(deep: bool = false) -> Resource
func duplicate_deep(deep_subresources_mode: Resource.DeepDuplicateMode = 1) -> Resource
func emit_changed() -> void
func get_rid() -> RID
func is_built_in() -> bool
func reset_state() -> void
func set_id_for_path(path: String, id: String) -> void
func set_path_cache(path: String) -> void
func setup_local_to_scene() -> void
func take_over_path(path: String) -> void
Inherited from RefCounted (4)
func init_ref() -> bool
func reference() -> bool
func unreference() -> bool
Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Resource (2)
signal changed()
Inherited from Object (2)

Enums & Constants

enum TileShape
TILE_SHAPE_SQUARE = 0

Rectangular tile shape.

TILE_SHAPE_ISOMETRIC = 1

Diamond tile shape (for isometric look).

Note: Isometric TileSet works best if all sibling TileMapLayers and their parent inheriting from Node2D have Y-sort enabled.

TILE_SHAPE_HALF_OFFSET_SQUARE = 2

Rectangular tile shape with one row/column out of two offset by half a tile.

TILE_SHAPE_HEXAGON = 3

Hexagonal tile shape.

enum TileLayout
TILE_LAYOUT_STACKED = 0

Tile coordinates layout where both axis stay consistent with their respective local horizontal and vertical axis.

TILE_LAYOUT_STACKED_OFFSET = 1

Same as TILE_LAYOUT_STACKED, but the first half-offset is negative instead of positive.

TILE_LAYOUT_STAIRS_RIGHT = 2

Tile coordinates layout where the horizontal axis stay horizontal, and the vertical one goes down-right.

TILE_LAYOUT_STAIRS_DOWN = 3

Tile coordinates layout where the vertical axis stay vertical, and the horizontal one goes down-right.

TILE_LAYOUT_DIAMOND_RIGHT = 4

Tile coordinates layout where the horizontal axis goes up-right, and the vertical one goes down-right.

TILE_LAYOUT_DIAMOND_DOWN = 5

Tile coordinates layout where the horizontal axis goes down-right, and the vertical one goes down-left.

enum TileOffsetAxis
TILE_OFFSET_AXIS_HORIZONTAL = 0

Horizontal half-offset.

TILE_OFFSET_AXIS_VERTICAL = 1

Vertical half-offset.

enum CellNeighbor
CELL_NEIGHBOR_RIGHT_SIDE = 0

Neighbor on the right side.

CELL_NEIGHBOR_RIGHT_CORNER = 1

Neighbor in the right corner.

CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE = 2

Neighbor on the bottom right side.

CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER = 3

Neighbor in the bottom right corner.

CELL_NEIGHBOR_BOTTOM_SIDE = 4

Neighbor on the bottom side.

CELL_NEIGHBOR_BOTTOM_CORNER = 5

Neighbor in the bottom corner.

CELL_NEIGHBOR_BOTTOM_LEFT_SIDE = 6

Neighbor on the bottom left side.

CELL_NEIGHBOR_BOTTOM_LEFT_CORNER = 7

Neighbor in the bottom left corner.

CELL_NEIGHBOR_LEFT_SIDE = 8

Neighbor on the left side.

CELL_NEIGHBOR_LEFT_CORNER = 9

Neighbor in the left corner.

CELL_NEIGHBOR_TOP_LEFT_SIDE = 10

Neighbor on the top left side.

CELL_NEIGHBOR_TOP_LEFT_CORNER = 11

Neighbor in the top left corner.

CELL_NEIGHBOR_TOP_SIDE = 12

Neighbor on the top side.

CELL_NEIGHBOR_TOP_CORNER = 13

Neighbor in the top corner.

CELL_NEIGHBOR_TOP_RIGHT_SIDE = 14

Neighbor on the top right side.

CELL_NEIGHBOR_TOP_RIGHT_CORNER = 15

Neighbor in the top right corner.

enum TerrainMode
TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0

Requires both corners and side to match with neighboring tiles' terrains.

TERRAIN_MODE_MATCH_CORNERS = 1

Requires corners to match with neighboring tiles' terrains.

TERRAIN_MODE_MATCH_SIDES = 2

Requires sides to match with neighboring tiles' terrains.