GridMap
Entity for 3D tile-based maps.
Entity for 3D tile-based maps.
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.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
GridMapConstructor
public GridMap();Properties15
BakeNavigationProperty
public bool BakeNavigation { get; set; }If true, this GridMap creates a navigation region for each cell that uses a GridMap.MeshLibrary item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the MeshLibrary's item.
CellCenterXProperty
public bool CellCenterX { get; set; }If true, grid items are centered on the X axis.
CellCenterYProperty
public bool CellCenterY { get; set; }If true, grid items are centered on the Y axis.
CellCenterZProperty
public bool CellCenterZ { get; set; }If true, grid items are centered on the Z axis.
CellOctantSizeProperty
public int CellOctantSize { get; set; }The size of each octant measured in number of cells. This applies to all three axis.
CellScaleProperty
public float CellScale { get; set; }Placed-item basis scale, affecting both meshes and physics shapes. Does not change CellSize or MapToLocal. A value of 0.5 shrinks blocks while retaining the original cell spacing.
CellSizeProperty
public Vector3 CellSize { get; set; }Grid spacing on three axes. Changes cell spacing/placement, not source MeshLibrary mesh dimensions. Match module dimensions separately; CellScale controls placed mesh and shape scale.
CollisionLayerProperty
public uint CollisionLayer { get; set; }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.
CollisionMaskProperty
public uint CollisionMask { get; set; }The physics layers this GridMap detects collisions in. See Collision layers and masks in the documentation for more information.
CollisionPriorityProperty
public float CollisionPriority { get; set; }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.
CollisionVisibilityModeProperty
public GridMap.DebugVisibilityMode CollisionVisibilityMode { get; set; }Show or hide the GridMap's collision shapes. If set to GridMap.DebugVisibilityMode.Default, this depends on the show collision debug settings.
DebugOctantColorProperty
public Color DebugOctantColor { get; set; }The Color used for rendering octant debug visuals when GridMap.DebugShowOctants is enabled.
DebugShowOctantsProperty
public bool DebugShowOctants { get; set; }If true, shows debug visuals for octants.
MeshLibraryProperty
public MeshLibrary MeshLibrary { get; set; }Shared grid-item resource: IDs, meshes, transforms and separate physics shapes. Meshes do not automatically create collision. Current persistence is verified with contiguous IDs 0 and 1; sparse 0/7 loses item 7 data through a .rdata roundtrip despite Error.Ok.
PhysicsMaterialProperty
public PhysicsMaterial PhysicsMaterial { get; set; }Overrides the default friction and bounce physics properties for the whole GridMap.
Methods60
Clearvoid
public void Clear();Clear all cells.
ClearBakedMeshesvoid
public void ClearBakedMeshes();Clears all baked meshes. See GridMap.MakeBakedMeshes.
GetBakeMeshInstanceRid
public Rid GetBakeMeshInstance(int idx);Returns Rid of a baked mesh with the given idx.
| Name | Type | Default |
|---|---|---|
idx | int | — |
RidGetBakeMeshesReckfell.Collections.Array
public Reckfell.Collections.Array GetBakeMeshes();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 GridMap.MakeBakedMeshes, 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.
Reckfell.Collections.ArrayGetBasisWithOrthogonalIndexBasis
public Basis GetBasisWithOrthogonalIndex(int index);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 Reckfell source code.
| Name | Type | Default |
|---|---|---|
index | int | — |
BasisGetCellItemint
public int GetCellItem(Vector3I position);Reads the stored cell ID. An ID does not prove a matching MeshLibrary item, ready physics or visible geometry.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
positionGrid cell coordinate.
intItem ID, or -1 for an empty cell. Internal IDs are 16-bit; validate the range before SetCellItem.
GetCellItemBasisBasis
public Basis GetCellItemBasis(Vector3I position);Returns the basis that gives the specified cell its orientation.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
BasisGetCellItemOrientationint
public int GetCellItemOrientation(Vector3I position);Reads a cell orientation index, not Euler angles. Use GetCellItemBasis or GetBasisWithOrthogonalIndex for its Basis.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
intIndex 0..23 for a correctly assigned orthogonal orientation; -1 for an empty cell. Do not supply out-of-contract SetCellItem orientations.
GetCellScalefloat
public float GetCellScale();floatGetCellSizeVector3
public Vector3 GetCellSize();Vector3GetCenterXbool
public bool GetCenterX();boolGetCenterYbool
public bool GetCenterY();boolGetCenterZbool
public bool GetCenterZ();boolGetCollisionLayeruint
public uint GetCollisionLayer();uintGetCollisionLayerValuebool
public bool GetCollisionLayerValue(int layerNumber);Returns whether or not the specified layer of the GridMap.CollisionLayer is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetCollisionMaskuint
public uint GetCollisionMask();uintGetCollisionMaskValuebool
public bool GetCollisionMaskValue(int layerNumber);Returns whether or not the specified layer of the GridMap.CollisionMask is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetCollisionPriorityfloat
public float GetCollisionPriority();floatGetCollisionVisibilityModeGridMap.DebugVisibilityMode
public GridMap.DebugVisibilityMode GetCollisionVisibilityMode();GridMap.DebugVisibilityModeGetDebugOctantColorColor
public Color GetDebugOctantColor();ColorGetDebugShowOctantsbool
public bool GetDebugShowOctants();boolGetMeshLibraryMeshLibrary
public MeshLibrary GetMeshLibrary();MeshLibraryGetMeshesReckfell.Collections.Array
public Reckfell.Collections.Array GetMeshes();Returns transform/mesh pairs for existing items. Not a list of entities or colliders; a stored unknown item ID can be absent from this result.
Reckfell.Collections.ArrayArray alternating Transform3D and Mesh. Array Count is twice the pair count, not a cell count.
GetNavigationMapRid
public Rid GetNavigationMap();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.
RidGetOctantCoordsFromCellCoordsVector3I
public Vector3I GetOctantCoordsFromCellCoords(Vector3I cellCoords);Returns the Vector3I octant coordinates of the octant that the cell at cell_coords belongs to.
| Name | Type | Default |
|---|---|---|
cellCoords | Vector3I | — |
Vector3IGetOctantSizeint
public int GetOctantSize();intGetOctantsInBoundsReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetOctantsInBounds(Aabb bounds);Returns an array of Vector3I octant coordinates that are inside the given bounds, including octants that have no cells in use.
| Name | Type | Default |
|---|---|---|
bounds | Aabb | — |
Reckfell.Collections.Array<Vector3I>GetOrthogonalIndexFromBasisint
public int GetOrthogonalIndexFromBasis(Basis basis);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 Reckfell source code.
| Name | Type | Default |
|---|---|---|
basis | Basis | — |
intGetPhysicsMaterialPhysicsMaterial
public PhysicsMaterial GetPhysicsMaterial();PhysicsMaterialGetUsedCellsReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedCells();Returns an array of Vector3 with the non-empty cell coordinates in the grid map.
Reckfell.Collections.Array<Vector3I>GetUsedCellsByItemReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedCellsByItem(int item);Returns an array of all cells with the given item index specified in item.
| Name | Type | Default |
|---|---|---|
item | int | — |
Reckfell.Collections.Array<Vector3I>GetUsedCellsInOctantReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedCellsInOctant(Vector3I octantCoords);Returns an array of Vector3Is with the cell coordinates of non-empty cells inside the octant at octant_coords.
| Name | Type | Default |
|---|---|---|
octantCoords | Vector3I | — |
Reckfell.Collections.Array<Vector3I>GetUsedCellsInOctantByItemReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedCellsInOctantByItem(Vector3I octantCoords, int item);Returns an array of Vector3Is with the cell coordinates of cells inside the octant at octant_coords that use the specified cell item.
| Name | Type | Default |
|---|---|---|
octantCoords | Vector3I | — |
item | int | — |
Reckfell.Collections.Array<Vector3I>GetUsedOctantsReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedOctants();Returns an array of Vector3Is with the octant coordinates of the non-empty octants in the grid map.
Reckfell.Collections.Array<Vector3I>GetUsedOctantsByItemReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedOctantsByItem(int item);Returns an array of Vector3Is with the octant coordinates of the octants that use the specified item in the grid map.
| Name | Type | Default |
|---|---|---|
item | int | — |
Reckfell.Collections.Array<Vector3I>GetUsedOctantsInBoundsReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> GetUsedOctantsInBounds(Aabb bounds);Returns an array of Vector3Is with the octant coordinates of non-empty octants that are inside the local bounds.
| Name | Type | Default |
|---|---|---|
bounds | Aabb | — |
Reckfell.Collections.Array<Vector3I>IsBakingNavigationbool
public bool IsBakingNavigation();boolLocalToMapVector3I
public Vector3I LocalToMap(Vector3 localPosition);Divides a local position by CellSize and floors each axis. Convert world positions through ToLocal first; integer-casting division is incorrect for negative coordinates.
| Name | Type | Default |
|---|---|---|
localPosition | Vector3 | — |
localPositionGridMap-local position, not an unconverted world-space ray-hit point.
Vector3ICell coordinate. With size 2, point (-0.01,-0.01,-0.01) belongs to (-1,-1,-1). For a point exactly on a surface, account for the boundary side and hit normal.
MakeBakedMeshesvoid
public void MakeBakedMeshes(bool genLightmapUV = false, float lightmapUVTexelSize = 0.1f);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 GridMap.GetBakeMeshes, 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.
| Name | Type | Default |
|---|---|---|
genLightmapUV | bool | false |
lightmapUVTexelSize | float | 0.1f |
MapToLocalVector3
public Vector3 MapToLocal(Vector3I mapPosition);Converts a cell coordinate to local position using CellSize and per-axis CellCenterX/Y/Z. Not necessarily the mesh center: MeshLibrary has separate item transforms.
| Name | Type | Default |
|---|---|---|
mapPosition | Vector3I | — |
mapPositionInteger cell coordinate.
Vector3Local cell position. With CellSize=(2,2,2), X/Z centering and Y centering disabled, cell (2,3,-1) gives (5,6,-1). Use ToGlobal for world space.
ResourceChangedvoid · Deprecated
public void ResourceChanged(Resource resource);This method does nothing.
| Name | Type | Default |
|---|---|---|
resource | Resource | — |
SetBakeNavigationvoid
public void SetBakeNavigation(bool bakeNavigation);| Name | Type | Default |
|---|---|---|
bakeNavigation | bool | — |
SetCellItemvoid
public void SetCellItem(Vector3I position, int item, int orientation = 0);Sets the single item in a cell, replacing the previous item. Logical state changes immediately; render and physics octants update later. Validate IDs against GetItemList: an unknown ID can be stored without visible geometry. The verified item field is 16-bit: 65536 becomes 0.
| Name | Type | Default |
|---|---|---|
position | Vector3I | — |
item | int | — |
orientation | int | 0 |
positionInteger cell coordinate, not a position in world units. Source bounds require each coordinate magnitude below 2^20.
itemMeshLibrary ID in 0..65535; a negative value erases the cell. Current library persistence requires contiguous IDs from 0 and reload verification: sparse IDs can lose data.
orientationIndex of one of 24 orthogonal orientations, not degrees. Obtain it through GetOrthogonalIndexFromBasis rather than supplying an arbitrary number.
SetCellScalevoid
public void SetCellScale(float scale);| Name | Type | Default |
|---|---|---|
scale | float | — |
SetCellSizevoid
public void SetCellSize(Vector3 size);| Name | Type | Default |
|---|---|---|
size | Vector3 | — |
SetCenterXvoid
public void SetCenterX(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetCenterYvoid
public void SetCenterY(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetCenterZvoid
public void SetCenterZ(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetCollisionLayervoid
public void SetCollisionLayer(uint layer);| Name | Type | Default |
|---|---|---|
layer | uint | — |
SetCollisionLayerValuevoid
public void SetCollisionLayerValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the GridMap.CollisionLayer, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetCollisionMaskvoid
public void SetCollisionMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetCollisionMaskValuevoid
public void SetCollisionMaskValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the GridMap.CollisionMask, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetCollisionPriorityvoid
public void SetCollisionPriority(float priority);| Name | Type | Default |
|---|---|---|
priority | float | — |
SetCollisionVisibilityModevoid
public void SetCollisionVisibilityMode(GridMap.DebugVisibilityMode visibilityMode);| Name | Type | Default |
|---|---|---|
visibilityMode | GridMap.DebugVisibilityMode | — |
SetDebugOctantColorvoid
public void SetDebugOctantColor(Color color);| Name | Type | Default |
|---|---|---|
color | Color | — |
SetDebugShowOctantsvoid
public void SetDebugShowOctants(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetMeshLibraryvoid
public void SetMeshLibrary(MeshLibrary meshLibrary);| Name | Type | Default |
|---|---|---|
meshLibrary | MeshLibrary | — |
SetNavigationMapvoid
public void SetNavigationMap(Rid navigationMap);Sets the Rid of the navigation map this GridMap node should use for its cell baked navigation meshes.
| Name | Type | Default |
|---|---|---|
navigationMap | Rid | — |
SetOctantSizevoid
public void SetOctantSize(int size);| Name | Type | Default |
|---|---|---|
size | int | — |
SetPhysicsMaterialvoid
public void SetPhysicsMaterial(PhysicsMaterial material);| Name | Type | Default |
|---|---|---|
material | PhysicsMaterial | — |
Signals and events2
CellSizeChangedEvent
public event GridMap.CellSizeChangedEventHandler CellSizeChanged;Emitted when GridMap.CellSize changes.
| Name | Type | Default |
|---|---|---|
cellSize | Vector3 | — |
ChangedEvent
public event Action Changed;Emitted when the MeshLibrary of this GridMap changes.
Fields and constants1
InvalidCellItemField
public const long InvalidCellItem = -1;Invalid cell item that can be used in GridMap.SetCellItem to clear cells (or represent an empty cell in GridMap.GetCellItem).
GridMap.DebugVisibilityMode
| Value | Description |
|---|---|
Default = 0 | Hide the collisions debug shapes in the editor, and use the debug settings to determine their visibility in game (i.e. |
ForceHide = 2 | Always hide the collisions debug shapes. |
ForceShow = 1 | Always show the collisions debug shapes. |