This seemed like an interesting challenge to try and figure out, so I took a few hours and gave it a shot. It’s probably not the best way to do it, but it sort of works.
I’ve got 3 main components that interact with each other and then some helper stuff.
Grid Spawner: I started off creating a grid with some static mesh squares on the floor using the construction script. I automated the process as much as I could so you really only have to insert the Row Amount to change the size of the grid. (It’s also pretty easy to just change the mesh and the OffsetAmount based on the size of the mesh to get a nice grid.) It’s very important that all the meshes have the same material for my system to work, because I use that for checking for available movement later. (Prolly not something I should have done, but I figured it’d be easy enough for this example.)
MyCharacter: I used a first person template, because I had one extra project with that made already anyway. So instead of a mouse pointer, aiming is done with the view direction of the camera. (Which is again not ideal, but I was too lazy to change it to a mouse pointer.) I do a line trace out from the camera and check what I’m hitting. First it checks whether it’s an AI character (that I confusingly called Actor for no reason), if so it sends a event to the AI. If not it checks whether you clicked on the grid, if so it checks the material of the grid to see if it’s highlighted by stuff the AI character does when it’s selected. If it is a valid move spot, it gets the location of the mesh and sets that as a vector variable (that way the characters always move to the centre of the mesh) and it turns the square white so you can see where you clicked. In the very end it sends the move command to the AI itself so it can do the stuff it needs to do. There’s also a bit where right click deselects the actor and sends an event through to it.
There’s also a bit for highlighting the square based on what you’re looking at (turns blue in the video). It doesn’t make the highlighted squares turn any different colour, because I’d have to redo the valid movement locations check then and I’m somewhat lazy. It turns a single square blue and then back to normal if you move your view off that square. It also double checks and turns any blue squares back to default before activating a new blue square, just because it kept leaving blue ones without clearing them and this was a quick fix. (It uses the array of meshes I set in the construction script of the Grid Spawner.)
AI Character (Actor): The thing I named somewhat confusingly as an actor. First it gets references to MyCharacter and GridSpawner, gets the ArrayOfMeshes and the OffsetAmount from the grid, which I’ll use in a bit. Then I use Event Select AI to highlight the area around that AI by running line traces down from above with offsets determined by the grid offset amount. I use some loops to run several traces in a single direction to have less repeating bits, but mostly I did each trace separately. That way you can have absolute control over the shape of movement area you want. I also make sure that all the traces are going to go exactly in the middle of each square, so that when there’s an obstacle in the way, it doesn’t highlight the grid plate and you cannot move there. There’s one more bit that checks whether the trace hits an actor, which could be used for detecting friendlies or enemies and have a separate attack function for dealing with that, but right now I just left it to do nothing.
There’s another bit that (starts off with a pointless branch node by accident) sends the move command, which just moves the AI to the location that was set in MyCharacter and upon success it returns that square to the default colour (because we changed that to white before). After that it highlights a new set of squares around it and lets you move around again. (In an actual game you’d probably want to either show a new smaller area or not have one at all if the move points are all spent.)
And deselecting just clears the highlights so that the next thing you select can’t move into those squares.
I didn’t bother adding cutoff areas for the highlighted grid when you want your AI to move behind something, but they’re pretty easy to make, especially if you use loops to draw them in a single direction. You can just stop the loop when it hits some kind of obstacle. In the end of the video I show how it kind of successfully moves around an obstacle, but that’s more luck than expected behaviour.
Also if it’s not obvious, I use a blueprint interface to send the events from MyCharacter to the Actor. It just has 3 functions that I just named and nothing else, they’re all empty. I had to tweak some collision settings on the AIs to make sure they block the visibility trace I’m sending out and of course there’s a nav mesh bounds volume around the grid so that the AI’s could even move.
And here’s the blueprints for everything:
Edit: There’s a few things I accidentally did that weren’t right, like when drawing the highlights, it did it as part of the loop as many times as the array had elements and not at the completion of the loop as it should have. Also if for drawing the line traces to highlight move paths you replace the “for loops” with “for loops with break” and use the failure of the class check near the end, it will prevent it from drawing more moves behind enemies.