Index · Object → Node → Node3D → GridMap

GridMap

Node for 3D tile-based maps.

Class Description

GridMap lets you place meshes on a grid interactively. It works both from the editor and from scripts, which can help you create in-game level editors.

GridMaps use a MeshLibrary which contains a list of tiles. Each tile is a mesh with materials plus optional collision and navigation shapes.

A GridMap contains a collection of cells. Each grid cell refers to a tile in the MeshLibrary. All cells in the map have the same dimensions.

Internally, a GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells.

Note: GridMap doesn't extend VisualInstance3D and therefore can't be hidden or cull masked based on VisualInstance3D.layers. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.

Properties

var bake_navigation: bool = false

If true, this GridMap creates a navigation region for each cell that uses a mesh_library item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the MeshLibrary's item.

var cell_center_x: bool = true

If true, grid items are centered on the X axis.

var cell_center_y: bool = true

If true, grid items are centered on the Y axis.

var cell_center_z: bool = true

If true, grid items are centered on the Z axis.

var cell_octant_size: int = 8

The size of each octant measured in number of cells. This applies to all three axis.

var cell_scale: float = 1.0

The scale of the cell items.

This does not affect the size of the grid cells themselves, only the items in them. This can be used to make cell items overlap their neighbors.

var cell_size: Vector3 = Vector3(2, 2, 2)

The dimensions of the grid's cells.

This does not affect the size of the meshes. See cell_scale.

var collision_layer: int = 1

The physics layers this GridMap is in.

GridMaps act as static bodies, meaning they aren't affected by gravity or other forces. They only affect other physics bodies that collide with them.

var collision_mask: int = 1

The physics layers this GridMap detects collisions in. See Collision layers and masks in the documentation for more information.

var collision_priority: float = 1.0

The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.

var collision_visibility_mode: GridMap.DebugVisibilityMode = 0

Show or hide the GridMap's collision shapes. If set to DEBUG_VISIBILITY_MODE_DEFAULT, this depends on the show collision debug settings.

var mesh_library: MeshLibrary

The assigned MeshLibrary.

var physics_material: PhysicsMaterial

Overrides the default friction and bounce physics properties for the whole GridMap.

Inherited from Node3D (17)
var position: Vector3 = Vector3(0, 0, 0)
var rotation: Vector3 = Vector3(0, 0, 0)
var rotation_order: EulerOrder = 2
var scale: Vector3 = Vector3(1, 1, 1)
var top_level: bool = false
var transform: Transform3D = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
var visibility_parent: NodePath = NodePath("")
var visible: bool = true
Inherited from Node (14)
var owner: Node

Methods

func clear() -> void

Clear all cells.

func clear_baked_meshes() -> void

Clears all baked meshes. See make_baked_meshes().

func get_bake_mesh_instance(idx: int) -> RID

Returns RID of a baked mesh with the given idx.

func get_bake_meshes() -> Array

Returns an array of ArrayMeshes and Transform3D references of all bake meshes that exist within the current GridMap. Even indices contain ArrayMeshes, while odd indices contain Transform3Ds that are always equal to Transform3D.IDENTITY.

This method relies on the output of make_baked_meshes(), which will be called with gen_lightmap_uv set to true and lightmap_uv_texel_size set to 0.1 if it hasn't been called yet.

func get_basis_with_orthogonal_index(index: int) -> Basis

Returns one of 24 possible rotations that lie along the vectors (x,y,z) with each component being either -1, 0, or 1. For further details, refer to the Godot source code.

func get_cell_item(position: Vector3i) -> int

The MeshLibrary item index located at the given grid coordinates. If the cell is empty, INVALID_CELL_ITEM will be returned.

func get_cell_item_basis(position: Vector3i) -> Basis

Returns the basis that gives the specified cell its orientation.

func get_cell_item_orientation(position: Vector3i) -> int

The orientation of the cell at the given grid coordinates. -1 is returned if the cell is empty.

func get_collision_layer_value(layer_number: int) -> bool

Returns whether or not the specified layer of the collision_layer is enabled, given a layer_number between 1 and 32.

func get_collision_mask_value(layer_number: int) -> bool

Returns whether or not the specified layer of the collision_mask is enabled, given a layer_number between 1 and 32.

func get_meshes() -> Array

Returns an array of Transform3D and Mesh references corresponding to the non-empty cells in the grid. The transforms are specified in local space. Even indices contain Transform3Ds, while odd indices contain Meshes related to the Transform3D in the index preceding it.

func get_navigation_map() -> RID

Returns the RID of the navigation map this GridMap node uses for its cell baked navigation meshes.

This function returns always the map set on the GridMap node and not the map on the NavigationServer. If the map is changed directly with the NavigationServer API the GridMap node will not be aware of the map change.

func get_octant_coords_from_cell_coords(cell_coords: Vector3i) -> Vector3i

Returns the Vector3i octant coordinates of the octant that the cell at cell_coords belongs to.

func get_octants_in_bounds(bounds: AABB) -> Vector3i[]

Returns an array of Vector3i octant coordinates that are inside the given bounds, including octants that have no cells in use.

func get_orthogonal_index_from_basis(basis: Basis) -> int

This function considers a discretization of rotations into 24 points on unit sphere, lying along the vectors (x,y,z) with each component being either -1, 0, or 1, and returns the index (in the range from 0 to 23) of the point best representing the orientation of the object. For further details, refer to the Godot source code.

func get_used_cells() -> Vector3i[]

Returns an array of Vector3 with the non-empty cell coordinates in the grid map.

func get_used_cells_by_item(item: int) -> Vector3i[]

Returns an array of all cells with the given item index specified in item.

func get_used_cells_in_octant(octant_coords: Vector3i) -> Vector3i[]

Returns an array of Vector3is with the cell coordinates of non-empty cells inside the octant at octant_coords.

func get_used_cells_in_octant_by_item(octant_coords: Vector3i, item: int) -> Vector3i[]

Returns an array of Vector3is with the cell coordinates of cells inside the octant at octant_coords that use the specified cell item.

func get_used_octants() -> Vector3i[]

Returns an array of Vector3is with the octant coordinates of the non-empty octants in the grid map.

func get_used_octants_by_item(item: int) -> Vector3i[]

Returns an array of Vector3is with the octant coordinates of the octants that use the specified item in the grid map.

func get_used_octants_in_bounds(bounds: AABB) -> Vector3i[]

Returns an array of Vector3is with the octant coordinates of non-empty octants that are inside the local bounds.

func local_to_map(local_position: Vector3) -> Vector3i

Returns the map coordinates of the cell containing the given local_position. If local_position is in global coordinates, consider using Node3D.to_local() before passing it to this method. See also map_to_local().

func make_baked_meshes(gen_lightmap_uv: bool = false, lightmap_uv_texel_size: float = 0.1) -> void

Generates a baked mesh that represents all meshes in the assigned MeshLibrary for use with LightmapGI. If gen_lightmap_uv is true, UV2 data will be generated for each mesh currently used in the GridMap. Otherwise, only meshes that already have UV2 data present will be able to use baked lightmaps. When generating UV2, lightmap_uv_texel_size controls the texel density for lightmaps, with lower values resulting in more detailed lightmaps. lightmap_uv_texel_size is ignored if gen_lightmap_uv is false. See also get_bake_meshes(), which relies on the output of this method.

Note: Calling this method will not actually bake lightmaps, as lightmap baking is performed using the LightmapGI node.

func map_to_local(map_position: Vector3i) -> Vector3

Returns the position of a grid cell in the GridMap's local coordinate space. To convert the returned value into global coordinates, use Node3D.to_global(). See also local_to_map().

func resource_changed(resource: Resource) -> void

This method does nothing.

func set_cell_item(position: Vector3i, item: int, orientation: int = 0) -> void

Sets the mesh index for the cell referenced by its grid coordinates.

A negative item index such as INVALID_CELL_ITEM will clear the cell.

Optionally, the item's orientation can be passed. For valid orientation values, see get_orthogonal_index_from_basis().

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

Based on value, enables or disables the specified layer in the collision_layer, given a layer_number between 1 and 32.

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

Based on value, enables or disables the specified layer in the collision_mask, given a layer_number between 1 and 32.

func set_navigation_map(navigation_map: RID) -> void

Sets the RID of the navigation map this GridMap node should use for its cell baked navigation meshes.

Inherited from Node3D (37)
func add_gizmo(gizmo: Node3DGizmo) -> void
func clear_gizmos() -> void
func force_update_transform() -> void
func get_gizmos() -> Node3DGizmo[]
func global_rotate(axis: Vector3, angle: float) -> void
func global_scale(scale: Vector3) -> void
func global_translate(offset: Vector3) -> void
func hide() -> void
func look_at(target: Vector3, up: Vector3 = Vector3(0, 1, 0), use_model_front: bool = false) -> void
func look_at_from_position(position: Vector3, target: Vector3, up: Vector3 = Vector3(0, 1, 0), use_model_front: bool = false) -> void
func orthonormalize() -> void
func rotate(axis: Vector3, angle: float) -> void
func rotate_object_local(axis: Vector3, angle: float) -> void
func rotate_x(angle: float) -> void
func rotate_y(angle: float) -> void
func rotate_z(angle: float) -> void
func scale_object_local(scale: Vector3) -> void
func set_disable_scale(disable: bool) -> void
func set_identity() -> void
func set_notify_local_transform(enable: bool) -> void
func set_notify_transform(enable: bool) -> void
func set_subgizmo_selection(gizmo: Node3DGizmo, id: int, transform: Transform3D) -> void
func show() -> void
func to_global(local_point: Vector3) -> Vector3
func to_local(global_point: Vector3) -> Vector3
func translate(offset: Vector3) -> void
func translate_object_local(offset: Vector3) -> void
func update_gizmos() -> void
Inherited from Node (106)
func _enter_tree() -> void
func _exit_tree() -> void
func _input(event: InputEvent) -> void
func _physics_process(delta: float) -> void
func _process(delta: float) -> void
func _ready() -> void
func _shortcut_input(event: InputEvent) -> void
func _unhandled_input(event: InputEvent) -> void
func _unhandled_key_input(event: InputEvent) -> void
func add_child(node: Node, force_readable_name: bool = false, internal: Node.InternalMode = 0) -> void
func add_sibling(sibling: Node, force_readable_name: bool = false) -> void
func add_to_group(group: StringName, persistent: bool = false) -> void
func atr(message: String, context: StringName = "") -> String
func atr_n(message: String, plural_message: StringName, n: int, context: StringName = "") -> String
func can_process() -> bool
func duplicate(flags: int = 15) -> Node
func find_child(pattern: String, recursive: bool = true, owned: bool = true) -> Node
func find_children(pattern: String, type: String = "", recursive: bool = true, owned: bool = true) -> Node[]
func find_parent(pattern: String) -> Node
func get_child(idx: int, include_internal: bool = false) -> Node
func get_child_count(include_internal: bool = false) -> int
func get_children(include_internal: bool = false) -> Node[]
func get_groups() -> StringName[]
func get_index(include_internal: bool = false) -> int
func get_node(path: NodePath) -> Node
func get_orphan_node_ids() -> int[]
func get_parent() -> Node
func get_path() -> NodePath
func get_path_to(node: Node, use_unique_path: bool = false) -> NodePath
func get_window() -> Window
func has_node(path: NodePath) -> bool
func is_ancestor_of(node: Node) -> bool
func is_greater_than(node: Node) -> bool
func is_in_group(group: StringName) -> bool
func move_child(child_node: Node, to_index: int) -> void
func notify_deferred_thread_group(what: int) -> void
func notify_thread_safe(what: int) -> void
func print_orphan_nodes() -> void
func print_tree() -> void
func print_tree_pretty() -> void
func propagate_call(method: StringName, args: Array = [], parent_first: bool = false) -> void
func propagate_notification(what: int) -> void
func queue_free() -> void
func remove_child(node: Node) -> void
func remove_from_group(group: StringName) -> void
func reparent(new_parent: Node, keep_global_transform: bool = true) -> void
func replace_by(node: Node, keep_groups: bool = false) -> void
func request_ready() -> void
func rpc(method: StringName) -> Error
func rpc_config(method: StringName, config: Variant) -> void
func rpc_id(peer_id: int, method: StringName) -> Error
func set_deferred_thread_group(property: StringName, value: Variant) -> void
func set_display_folded(fold: bool) -> void
func set_editable_instance(node: Node, is_editable: bool) -> void
func set_multiplayer_authority(id: int, recursive: bool = true) -> void
func set_physics_process(enable: bool) -> void
func set_physics_process_internal(enable: bool) -> void
func set_process(enable: bool) -> void
func set_process_input(enable: bool) -> void
func set_process_internal(enable: bool) -> void
func set_process_shortcut_input(enable: bool) -> void
func set_process_unhandled_input(enable: bool) -> void
func set_scene_instance_load_placeholder(load_placeholder: bool) -> void
func set_thread_safe(property: StringName, value: Variant) -> void
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

signal cell_size_changed(cell_size: Vector3)

Emitted when cell_size changes.

signal changed()

Emitted when the MeshLibrary of this GridMap changes.

Inherited from Node3D (1)
Inherited from Node (11)
signal child_entered_tree(node: Node)
signal child_exiting_tree(node: Node)
signal ready()
signal renamed()
signal replacing_by(node: Node)
signal tree_entered()
signal tree_exited()
signal tree_exiting()
Inherited from Object (2)

Enums & Constants

enum DebugVisibilityMode
DEBUG_VISIBILITY_MODE_DEFAULT = 0

Hide the collisions debug shapes in the editor, and use the debug settings to determine their visibility in game (i.e. SceneTree.debug_collisions_hint or SceneTree.debug_navigation_hint).

DEBUG_VISIBILITY_MODE_FORCE_SHOW = 1

Always show the collisions debug shapes.

DEBUG_VISIBILITY_MODE_FORCE_HIDE = 2

Always hide the collisions debug shapes.

const INVALID_CELL_ITEM = -1

Invalid cell item that can be used in set_cell_item() to clear cells (or represent an empty cell in get_cell_item()).