Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GridMap

Inherits: Node3D < Node < Object

Node for 3D tile-based maps.

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.

Tutorials

Properties

bool

bake_navigation

false

bool

cell_center_x

true

bool

cell_center_y

true

bool

cell_center_z

true

int

cell_octant_size

8

float

cell_scale

1.0

Vector3

cell_size

Vector3(2, 2, 2)

int

collision_layer

1

int

collision_mask

1

float

collision_priority

1.0

MeshLibrary

mesh_library

PhysicsMaterial

physics_material

Methods

void

clear ( )

void

clear_baked_meshes ( )

RID

get_bake_mesh_instance ( int idx )

Array

get_bake_meshes ( )

Basis

get_basis_with_orthogonal_index ( int index ) const

int

get_cell_item ( Vector3i position ) const

Basis

get_cell_item_basis ( Vector3i position ) const

int

get_cell_item_orientation ( Vector3i position ) const

bool

get_collision_layer_value ( int layer_number ) const

bool

get_collision_mask_value ( int layer_number ) const

Array

get_meshes ( ) const

RID

get_navigation_map ( ) const

int

get_orthogonal_index_from_basis ( Basis basis ) const

Vector3i[]

get_used_cells ( ) const

Vector3i[]

get_used_cells_by_item ( int item ) const

Vector3i

local_to_map ( Vector3 local_position ) const

void

make_baked_meshes ( bool gen_lightmap_uv=false, float lightmap_uv_texel_size=0.1 )

Vector3

map_to_local ( Vector3i map_position ) const

void

resource_changed ( Resource resource )

void

set_cell_item ( Vector3i position, int item, int orientation=0 )

void

set_collision_layer_value ( int layer_number, bool value )

void

set_collision_mask_value ( int layer_number, bool value )

void

set_navigation_map ( RID navigation_map )


Signals

cell_size_changed ( Vector3 cell_size )

Emitted when cell_size changes.


changed ( )

Emitted when the MeshLibrary of this GridMap changes.


Constants

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).


Property Descriptions

bool bake_navigation = false

  • void set_bake_navigation ( bool value )

  • bool is_baking_navigation ( )

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.


bool cell_center_x = true

  • void set_center_x ( bool value )

  • bool get_center_x ( )

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


bool cell_center_y = true

  • void set_center_y ( bool value )

  • bool get_center_y ( )

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


bool cell_center_z = true

  • void set_center_z ( bool value )

  • bool get_center_z ( )

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


int cell_octant_size = 8

  • void set_octant_size ( int value )

  • int get_octant_size ( )

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


float cell_scale = 1.0

  • void set_cell_scale (