Class GridMap
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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 Layers. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.
public class GridMap : Node3D, IDisposable
- Inheritance
-
GridMap
- Implements
- Inherited Members
Constructors
GridMap()
public GridMap()
Fields
InvalidCellItem
Invalid cell item that can be used in SetCellItem(Vector3I, int, int) to clear cells (or represent an empty cell in GetCellItem(Vector3I)).
public const long InvalidCellItem = -1
Field Value
Properties
BakeNavigation
If true
, this GridMap creates a navigation region for each cell that uses a MeshLibrary item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the MeshLibrary's item.
public bool BakeNavigation { get; set; }
Property Value
CellCenterX
If true
, grid items are centered on the X axis.
public bool CellCenterX { get; set; }
Property Value
CellCenterY
If true
, grid items are centered on the Y axis.
public bool CellCenterY { get; set; }
Property Value
CellCenterZ
If true
, grid items are centered on the Z axis.
public bool CellCenterZ { get; set; }
Property Value
CellOctantSize
The size of each octant measured in number of cells. This applies to all three axis.
public int CellOctantSize { get; set; }
Property Value
CellScale
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.
public float CellScale { get; set; }
Property Value
CellSize
The dimensions of the grid's cells.
This does not affect the size of the meshes. See CellScale.
public Vector3 CellSize { get; set; }
Property Value
CollisionLayer
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.
public uint CollisionLayer { get; set; }
Property Value
CollisionMask
The physics layers this GridMap detects collisions in. See Collision layers and masks in the documentation for more information.
public uint CollisionMask { get; set; }
Property Value
CollisionPriority
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.
public float CollisionPriority { get; set; }
Property Value
MeshLibrary
The assigned MeshLibrary.
public MeshLibrary MeshLibrary { get; set; }
Property Value
PhysicsMaterial
Overrides the default friction and bounce physics properties for the whole GridMap.
public PhysicsMaterial PhysicsMaterial { get; set; }
Property Value
Methods
Clear()
Clear all cells.
public void Clear()
ClearBakedMeshes()
Clears all baked meshes. See MakeBakedMeshes(bool, float).
public void ClearBakedMeshes()
GetBakeMeshInstance(int)
Returns Rid of a baked mesh with the given idx
.
public Rid GetBakeMeshInstance(int idx)
Parameters
idx
int
Returns
GetBakeMeshes()
Returns an array of ArrayMeshes and Transform3D references of all bake meshes that exist within the current GridMap.
public Array GetBakeMeshes()
Returns
GetBasisWithOrthogonalIndex(int)
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.
public Basis GetBasisWithOrthogonalIndex(int index)
Parameters
index
int
Returns
GetCellItem(Vector3I)
The MeshLibrary item index located at the given grid coordinates. If the cell is empty, InvalidCellItem will be returned.
public int GetCellItem(Vector3I position)
Parameters
position
Vector3I
Returns
GetCellItemBasis(Vector3I)
Returns the basis that gives the specified cell its orientation.
public Basis GetCellItemBasis(Vector3I position)
Parameters
position
Vector3I
Returns
GetCellItemOrientation(Vector3I)
The orientation of the cell at the given grid coordinates. -1
is returned if the cell is empty.
public int GetCellItemOrientation(Vector3I position)
Parameters
position
Vector3I
Returns
GetCollisionLayerValue(int)
Returns whether or not the specified layer of the CollisionLayer is enabled, given a layerNumber
between 1 and 32.
public bool GetCollisionLayerValue(int layerNumber)
Parameters
layerNumber
int
Returns
GetCollisionMaskValue(int)
Returns whether or not the specified layer of the CollisionMask is enabled, given a layerNumber
between 1 and 32.
public bool GetCollisionMaskValue(int layerNumber)
Parameters
layerNumber
int
Returns
GetMeshes()
Returns an array of Transform3D and Mesh references corresponding to the non-empty cells in the grid. The transforms are specified in local space.
public Array GetMeshes()
Returns
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.
public Rid GetNavigationMap()
Returns
GetOrthogonalIndexFromBasis(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 Godot source code.
public int GetOrthogonalIndexFromBasis(Basis basis)
Parameters
basis
Basis
Returns
GetUsedCells()
Returns an array of Vector3 with the non-empty cell coordinates in the grid map.
public Array<Vector3I> GetUsedCells()
Returns
GetUsedCellsByItem(int)
Returns an array of all cells with the given item index specified in item
.
public Array<Vector3I> GetUsedCellsByItem(int item)
Parameters
item
int
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
LocalToMap(Vector3)
Returns the map coordinates of the cell containing the given localPosition
. If localPosition
is in global coordinates, consider using ToLocal(Vector3) before passing it to this method. See also MapToLocal(Vector3I).
public Vector3I LocalToMap(Vector3 localPosition)
Parameters
localPosition
Vector3
Returns
MakeBakedMeshes(bool, float)
Bakes lightmap data for all meshes in the assigned MeshLibrary.
public void MakeBakedMeshes(bool genLightmapUV = false, float lightmapUVTexelSize = 0.1)
Parameters
MapToLocal(Vector3I)
Returns the position of a grid cell in the GridMap's local coordinate space. To convert the returned value into global coordinates, use ToGlobal(Vector3). See also MapToLocal(Vector3I).
public Vector3 MapToLocal(Vector3I mapPosition)
Parameters
mapPosition
Vector3I
Returns
ResourceChanged(Resource)
Obsoleted. Use Changed instead.
[Obsolete("This method is deprecated.")]
public void ResourceChanged(Resource resource)
Parameters
resource
Resource
SetCellItem(Vector3I, int, int)
Sets the mesh index for the cell referenced by its grid coordinates.
A negative item index such as InvalidCellItem will clear the cell.
Optionally, the item's orientation can be passed. For valid orientation values, see GetOrthogonalIndexFromBasis(Basis).
public void SetCellItem(Vector3I position, int item, int orientation = 0)
Parameters
SetCollisionLayerValue(int, bool)
Based on value
, enables or disables the specified layer in the CollisionLayer, given a layerNumber
between 1 and 32.
public void SetCollisionLayerValue(int layerNumber, bool value)
Parameters
SetCollisionMaskValue(int, bool)
Based on value
, enables or disables the specified layer in the CollisionMask, given a layerNumber
between 1 and 32.
public void SetCollisionMaskValue(int layerNumber, bool value)
Parameters
SetNavigationMap(Rid)
Sets the Rid of the navigation map this GridMap node should use for its cell baked navigation meshes.
public void SetNavigationMap(Rid navigationMap)
Parameters
navigationMap
Rid
Events
CellSizeChanged
Emitted when CellSize changes.
public event GridMap.CellSizeChangedEventHandler CellSizeChanged
Event Type
Changed
Emitted when the MeshLibrary of this GridMap changes.
public event Action Changed