Utilizing Examples¶
BP_GridInteractions¶
BP_GridInteractions
is a sample blueprint included with MegaGrid, designed to demonstrate various grid interaction implementations. I highly recommend exploring this blueprint to understand common interaction patterns. Doing so will give you a solid foundation for designing your own custom interactions. The actor can be found in Plugins/MegaGridContent/Blueprints/Core/
.
Features:
- Adding
TileType
/TileState
under brush. - Removing the given
TileType
/TileState
under brush. - Toggling visibility of the given
TileType
/TileState
. - Clear all states / types.
- Basic Pathfinding.
- Realtime Async Pathfinding.
- Move actor on path.
Settings¶
In order for the features to work, you'll need to assign a GridManager
reference and also enable DoPathfinding
.
I strongly encourage you to open the blueprint and adjust the execution pins to explore the full feature set. For example, the below setup changes the tile type by default, but by simply redirecting the execution flow, you can transform it into a state-setting system.
Controls¶
LMB
- Start pathfinding. Set Start and Target.F
- AddTileType
/TileState
under brush.K
- RemoveTileType
/TileState
under brush.E
- ToggleTileType
/TileState
visibility.C
- Clear all states / types.
Pathfinding Example¶
By default BP_GridInteraction
uses a static sync pathfinding workflow. But you can easily switch to the real-time pathfinding by repinning these functions.
-
In the end of
BeginPlay
, connect the exec pin to theSetTimerByFunction()
fromSetShowMouseCursor()
. This calls the async pathfinding every 0.02 seconds. -
Next we'll need to disable static pathfinding by going to the
LMB
input and removing the exec pin to theDoPathfinding
branch. -
With these changes, you'll now have a real-time async pathfinding in place.
Drawing Paths¶
To visualize a path after pathfinding completes, we need to update the states of relevant tiles. Essentially, we track the previous path, remove its "path" state, and apply the same state to the new path. You can refer to the implementation in the DrawPath()
event for guidance.
BP_GridManager¶
BP_GridManager
also includes an example implementation for Highlighting the Tile Under the Cursor. I placed this feature here because cursor highlights are a common function, and it makes sense to integrate them into a manager class. In contrast, the examples in BP_GridInteractions
tend to be agent-specific. You can find this implementation in BeginPlay
, where a TimerByFunction
is used to call HighlightTileUnderCursor()
at regular intervals, handling all necessary state changes.
Also feel free to explore the "button" functions since most of them can be called in runtime as well.
Example Projects¶
MegaGrid includes an example project featuring additional implementations such as Multi-Agent Pathfinding, Tiles Under Object and Runtime Level Changes. I highly encourage you to explore these as well.
Note
The example project is different from the demo game. While some features may be missing, they can be easily implemented.
Making Your Own¶
By using these examples, you'll gain a solid understanding of how to create your own interactive grid systems. At its core, the process involves accessing / modifying tile data—whether it's TileType
, TileState
, MovementCost
, visibility, or other attributes. If you have difficulty implementing certain features, feel free to reach out!