A lightweight, extensible, grid-first framework for Unity. MMAR Grid lets you:
- Generate and manage 2D grid worlds (X/Z plane) with integer precision
- Place and drag GridObjects that align/snap to the grid
- Query and convert between world and grid coordinates (Vector3 ⇄ Vector2Int)
- Build gameplay extensions on top: pathfinding, movement, explosions, etc.
This project already includes production-ready extensions:
- GridPathfinding (A*)
- GridMovementController (character controller)
- ExplosionManager (grid-aligned explosions with cardinal/diagonal options)
- Core (Base)
- GridManager: grid definition, coordinate conversion, placement helpers
- GridGroundObject: one per tile; holds an optional GridObject
- GridObject: base class for placeable things (bombs, crates, players...)
- Extensions
- GridPathfinding: A* search over the grid
- GridMovementController: Bomberman-style 4/8-way tile movement with dash
- ExplosionManager: tile-by-tile explosion visualisation and blocking
You can use any one of the following three methods:
- Download and import from Asset Store.
- Unity Package Manager → Add package by Git URL
https://github.com/mmar58/MMAR-Grid.git - Clone the repo anywhere on your machine, and use
Install package from diskfrom Package Manager. - Copy the repo in your unity project
The heart of the system. Responsibilities:
- Holds grid size
width×heightandgridStartPoint - Owns
groundGridObjects: Dictionary<Vector2Int, GridGroundObject> - Converts coordinates:
Vector2Int WorldToGrid(Vector3 world)→ clamps into boundsVector3 GridToWorld(Vector2Int grid)bool IsValidGridPosition(Vector2Int pos)
- Placement helpers:
PlaceObjectFromPrefab(GridObject prefab, Vector2Int pos)AddGridObject(GridObject prefab)for drag-and-drop authoring
Each cell has a GridGroundObject that may hold one GridObject via onGridObject.
Base class for anything that lives on the grid.
- Tracks
gridPositionand y-offset on placement - Snaps itself to the nearest valid tile on start (
PlaceToNearestGrid()) - Provides drag UX via
MouseInputManagerintegration
- Holds a reference to the
onGridObject - Surfaces mouse hover events through
GridManagerUnityEvents
A* pathfinding over the MMAR grid.
- 4-way movement (cardinals) with Manhattan heuristic
- Coroutine mode with partial updates and debug drawing
- Synchronous mode for one-off queries
- Utility methods: direct line checks, walkables in range
Important notes:
- Ensure
GridManageris assigned/available before callingFindPath - Keep walkability fresh:
- Either call
UpdateNodeWalkability(pos, walkable)when tiles change - Or query
IsPositionWalkable(pos)dynamically when expanding neighbors
- Either call
- For large maps, consider replacing the open set with a binary heap for speed
- If you need 8-way movement, extend
GetNeighbors()with diagonals and switch to an octile heuristic
Plug-and-play player controller built on the grid.
- 4/8-way inputs (Unity Input System) with optional diagonal corner-cut protection
- Smooth per-tile motion (MoveTowards) with input buffering
- Optional dash across N tiles with easing
- Smooth look-at rotation toward movement/dash direction
- Helpers:
CurrentGridPositionGetFacingDirection()andGetFrontGridPosition()IsFrontPositionClear()
Wire it by adding PlayerInput and binding a "Move" (Vector2) and "Dash" action.
Tile-aligned explosions that respect blocking.
- Cardinal rays plus optional diagonals
- Stops on blocking objects; includes destructibles on impact
- Spawns an effect prefab per affected tile, with optional ring spread
Usage:
// From a Bomb, when exploding:
ExplosionManager.Instance.TriggerExplosion(centerGrid, range, allowDiagonal);
// Bomb object can then destroy itselfTo integrate damage, iterate affected tiles and apply to any GridObject (or a custom interface).
- Add a GridManager to a scene
- Set width/height and gridStartPoint
- Assign
Grid Ground Objectin Game Objects prefab of GridManager - Assign
gridGroundParentandgridObjectParent(optional) - Generate tiles via the button or call
GenerateGridGround()
- Spawn/place objects
- Derive your items from
GridObject - Call
PlaceObjectFromPrefab(prefab, pos)or drag in editor
- Add Extensions as needed
- Pathfinding: add
GridPathfindingand callFindPath(startWorld, endWorld)orFindPathAsync - Movement: add
GridMovementController+PlayerInput - Explosions: add
ExplosionManagerand assign the effect prefab