An Unreal Engine 4 plugin for turn based navigation on a grid.
NavGrid supports grids with arbitrary layout including ladders and multiple levels of tiles. This makes it possible to have tile based movement in complex levels, like for instance multi-floor buildings.
The quickest way to get started is probably to download the demo project. The demo contains a sinle level demonstrating flat tiles, ladders and autogenerated virtual tiles.
- Save/clone into the
Plugins/
directory at the project root - Compile. You will need to right click on the
.uproject
in your project and selectGenerate Visual Studio project files
so VS is aware of the new source files. - Add
NavGrid
andAIModule
toPublicDependencyModuleNames
in your.Build.cs
A few more steps are needed after compiling the plugin:
- Enable the plugin for your project in the plugin-browser (
Edit->Plugins
) - Create a Collision Channel in the project setting and set its default response to
Ignore
- Place some
ANavTileActor
s and a fewAExampleGridPawn
s in your level - Set the PlayerController class to
ANavGridPC
- Hit Play!
Examining the headers for AGridPawn
, ANavGridPC
and UGridMovementComponent
are probably good starting points for figuring out how this plugin works. You probably want to extend AGridPawn
and create you own player controller for your project.
A few of the classes are summarized below.
Represents the grid. It is responsible for pathfinding.
Useful functions:
TilesInRange
: Get tiles within the specified distance. Optionally do collision testing and exclude tiles with obstructions.GetTile
: Get a tile from world-space coordinates.
Useful events:
OnTileClicked
OnTileCursorOver
OnTileEndCursorOver
Useful properties:
ECC_NavGridWalkable
: The channel used when tracing for tiles. Set this to the channel you created in step 4 of the quickstart.EnableVirtualTiles
: Enables placement of virtual tiles on empty spaces. Useful if you don't want to manually place tiles on every walkable part of your levels.
A single tile that can be traversed by a AGridPawn
. It will automaticly detect any neighbouring tiles.
Useful functions:
GetNeighbours
: Get all neighbouring tiles.Obstructed
: Given a capsule and a starting position, is there anything obstructing the movement into this tile?GetUnobstructedNeighbours
: Get all neighbouring tiles that a pawn can move into from this tile.Traversable
: Given a movement mode and a max walk angle, is it legal to enter this tile?LegalPositionAtEndOfTurn
: Given a movement mode and a max walk angle, is it legal to end a turn on this tile?
Useful properties:
Cost
: The amount of movement expended when moving into this tile.Mesh
: Static mesh used for rendering this tile.SelectCursor
andHoverCursor
: Mesh that can be shown just above the tile as part of the UI.- Various
*Highlight
: Mesh that can be shown just above the tile in order to highlight it in some way.
A subclass of UNavTileComponent
that can be used to represent a ladder.
Actor containing a single UNavTileComponent
or UNavLadderComponent
that can be placed directly into the world.
Base class for pawns that move on a NavGrid.
Useful functions:
OnTurnStart
andOnTurnEnd
: Called when this pawn's turn begins or ends. Override to add your own code.
Useful properties:
CapsuleComponent
: The size and relative location of this is used in pathfinding when determening if a tile is obstructed or not.MovementComponent
: A UNavGridMovementComponent (described below) for moving on the NavGridSelectedHighlight
: Mesh shown when the pawn is selected.SnapToGrid
: Snaps the pawn to grid at game start if set.
A movement component for moving on a navgrid.
Useful functions:
CreatePath
: Find a path to a tile. Returnsfalse
if the tile is unreachable.FollowPath
: Follow an existing path.PaseMoving
: Temporarily stop moving, callFollowPath
to resume.ShowPath
: Visualize the path.HidePath
: Stop visualizing the path.GetMovementMode
: Get the current movement mode (none, walking, climbing up or climping down).
Useful properties:
MovementRange
: How far (in tile cost) can this pawn move in a single move.Max*Speed
: Max speed for various movement modes.bUseRootMotion
: Use root motion to determine movement speed. If the current animation does not contain root motionMax*Speed
is used instead.AvailableMovementModes
: Movement modes available for this pawn. Can be useful if you for instance want to disable climbing for some pawns.
Useful events:
OnMovementEnd
: Triggered when the pawn has reached its destination.OnMovementModeChanged
: Triggered when the movement mode has changed. E.g. when the pawn has started climbing up a ladder instead of walking.
The path preview is thin and changes form and posision from one instance to another. If the antialiasing method is set to TemporalAA
, Unreal will attempt to make this motion appear smooth. This might not look good if there is some distance between the camera and the path.
There are two possible solutions to this: Either ensure that the camera is close when drawing a path or change the antialiasing method in Project Settings->Rendering
.
Version 2.2.2 - 23.07.2017
- Compile even if headers are included in 'incorrect' order
- Fix building without editor
- Fix building for Android
- Handle touch events
Version 2.2.1 - 04.07.2017
- Place virtual tiles before we do pathfinding
- Disable shadows for UI elements
- Use the same height offset for UI elements
Version 2.2 - 05.06.2017
- Support Unreal Engine 4.16
- Add automatic placement of 'virtual tiles' on empty areas
- Add option on ANavGrid for specifying the channel used when tracing for tiles
Version 2.1 - 11.09.2016
- Support Unreal Engine 4.13
- Ignore props when deciding if a tile is clicked or hovered over
Version 2.0 - 13.08.2016
- Support Unreal Engine 4.12
- Add ladders
- Add multiple levels of tiles
- Optionaly use root motion for movement speed
Version 1.0.1 - 29.11.2015
- Prevent mapcheck warnings about StaticMesh attributes being NULL when building
Version 1.0 - 08.11.2015
- First version