ATBTT - Experiments - Terrain Costs
Introduction to Pathfinding and Terrain Costs
Overview of the Question
- The speaker introduces a question from Monty regarding whether tile costs can be derived from units instead of tiles, allowing different movement capabilities on various terrains.
- The original idea involved using an integer structure for terrain costs within unit blueprints and an enum for terrain types in tile blueprints.
Initial Approach
- The speaker discusses the initial approach that did not work as intended, hinting at complexities in pathfinding and grid management.
- A demonstration begins with two units: one capable of traversing water freely and another facing movement penalties on water tiles.
Creating Terrain Types
Enum Creation
- An enum named
eTerrainis created to categorize terrain types such as dirt, water, and forest.
- A blueprint based on the grid actor is established to represent each tile's terrain type, making it editable in the level editor.
Visual Representation
- Static meshes are added to visualize different terrains; materials change according to the selected terrain type (brown for dirt, blue for water, green for forest).
Setting Up Tiles
Tile Placement
- The speaker places various tiles on a hexagonal grid while discussing procedural generation versus manual placement.
- A boat unit is positioned on water while another unit remains outside of it; both currently move without any special behavior related to terrain.
Modifying Grid Manager
Grid Awareness
- The grid manager is updated to recognize new tile data by adding a variable called
gridTerrain, which maps grid indices to their respective terrain types.
Data Population
- During gameplay initialization (
Begin Play), each tile's terrain type is added to thegridTerrainmap using its index.
Debugging Terrain Information
Debugging Setup
- An event graph modification allows debugging by printing out the terrain type when hovering over tiles with a key press (X).
Validation Check
- Successful validation shows correct identification of terrains (water, forest, dirt), confirming that data has been correctly populated into the grid manager.
Defining Unit Movement Costs
Unit Blueprint Modification
- In
bpUnit, a new variable calledterrainCostsis introduced as a map linking terrain types with their respective movement costs.
Default Values Assignment
- Default values are set: zero cost for moving onto water (indicating inability), one for dirt, and two for forest. Adjustments are made based on user requirements.
Implementing Custom Pathfinding Logic
New Pathfinding Class Creation
- A new blueprint class (
bPathTerrain) extends existing pathfinding functionality by overriding necessary functions related to valid tile checks during pathfinding operations.
Cost Calculation Integration
- The modified pathfinding logic incorporates checks against defined movement costs per unit when attempting to enter specific tiles during navigation.
Optimizing Pathfinding Performance
Efficient Function Calls
- Emphasis is placed on minimizing computations within frequently called functions like
addTileIfValid, suggesting pre-computation strategies before running core pathfinding logic.
Handling Edge Cases
- Special attention is given to scenarios where no unit exists at a starting index or if there’s no defined cost associated with entering certain terrains.
Final Adjustments and Testing
Testing Movement Behavior
- After implementing changes, testing reveals that units can now navigate according to their defined movement costs across different terrains effectively.
Conclusion
- The session concludes with an invitation for feedback regarding these modifications and suggestions for future tutorials focusing on toolkit enhancements.
Turn any video into a summary like this
YouTube links, meetings, lectures. With transcripts, search, and chat.




