This project implements the A* pathfinding algorithm in Unreal Engine 5 via an actor component (UPathFinding). The algorithm calculates the shortest path between two points in a grid while avoiding obstacles, using weighted cells and distance heuristics.
- Grid of Cells: Configurable in terms of size and dimensions.
- Optimal Path Detection: Uses distance weighting to find the shortest path.
- Path Visualization: Cells change color based on their status (start, destination, wall, visited cell, etc.).
- Obstacle Support: Ability to define wall cells that block the path.
- Real-Time Operation: Can be activated with step-by-step iterations to observe the progressive path calculation.
- Generate project files, compile the code, and press play in the editor.
- Left Click: Toggle wall cells.
- Right Click: Toggle the start and end cell positions.
- Click on "NEXT STEP" to observe the progressive path calculation.
- Click on "RESET CELLS" to clear the grid and reset the algorithm.
- PathFinding.h: Declaration of the
UPathFindingclass and its members, along with public and private functions required for the A* algorithm. - PathFinding.cpp: Implementation of functions, including cell initialization, distance calculations, cell selection, and cell management methods such as
ToggleWall,ToggleBeginEnd, andNextIteration.
- Grid Dimensions: In the Unreal Editor, set
HorizontalCells,VerticalCells, andCellSizeproperties to configure the grid. - Setting Start and End Points: Use
ToggleBeginEndby clicking on two points to define the start and end cells. - Adding Walls: Use the
ToggleWallfunction to add obstacles to specific cells in the grid.
- Start Iteration: Call
NextIterationto compute the path step by step. - Resetting: If needed, use
ResetCellsto clear the grid and reset the algorithm.
- Cells take on different colors to indicate their status:
- White: Unvisited cell.
- Black: Wall.
- Green: Weighted cell.
- Red: Cell being processed.
- Blue: Final path.
- Arrows and text labels help visualize relationships between cells and their weights.
- Add
PathFinding.cppandPathFinding.hfiles to your Unreal Engine 5 project. - Ensure that the
UPathFindingcomponent is attached to the desired actor. - Compile the project and adjust the parameters in the Unreal Editor.
- Optimization with Priority Queues: For more efficient calculation of weighted cells.
- Customizable Heuristic: Adjust the distance heuristic to adapt the algorithm to different types of terrain.
- User Interface: Add an interface to simplify interaction with the grid and pathfinding settings.
This project is intended for learning purposes and is free for personal and educational use.
The following images show how the A* pathfinding grid updates:





