Disable diagonal movement 2d top down game

That means pressing a button would hop you from one grid space to another, locked, not to end up somewhere halfway or diagonally displaced. Easiest way is to set up a teleport system and not use the character or pawn movement component at all. Don’t even use the pathing system that is molten into it. It’s a mess with a 101 features you specifically do not want and will mess up grid movement. Just use a pawn and completely remove any movement component of the engine on that pawn.

Next set up a grid on a GameInstanceSubsystem, it’s a subsystem you can get a reference to from anywhere and persists through level loading. On that subsystem you register the size of the grid (int vector, or int point for 2D), size in cm of a grid tile (float), and obstacles per a point on the grid (TMap<FIntPoint, bool> where bool indicates obstacle).

Programming Subsystems in Unreal Engine | Unreal Engine 5.2 Documentation

If you need to spawn anything in the world, you would get a location for that spawn by taking a position on the grid (for example vector X4, Y8) and multiplying that by the size of a grid tile. Just like a chess board if a chess tile would be defined 100cm then hopping from tile X1Y1 to X1Y2 would teleport you 100cm up.

An obstacle on the grid could be a wall or a pawn, it doesn’t matter just anything you don’t want to share a space with (winwin you don’t even need to set up mesh collision). When you press a directional button on your pawn, ask the grid if there is an obstacle in the neighboring grid space relative to your character, if not teleport the character there. You get movement like in crypt of the necrodancer. You can optionally store the position of obstacles including your character on the grid subsystem as int vector, then you have a central tracker and don’t need to awkwardly round your world position from float to int anytime you need to check your characters grid position.

https://www.youtube.com/watch?v=Rs4Sc6-PjQI

If at some point you do need pathing for AI maybe then that is made easy with vector fields.

https://www.youtube.com/watch?v=ZJZu3zLMYAc