I’ve been trying to make a wall building system for 2 weeks now and i’ve been struggling for the past 6 days trying to figure out how i can snap an actor (in this case it’s just an actor that contains an arrow) to the closest vertex on the grid compared to the mouse location.
So this is one of those “behind the curtain” things. The mesh you have is great for telling the player where they can place things. But it won’t have the functionality needed for this- you need to generate a series of points (which can be done procedurally) that the player can attach these things to. Don’t worry, they can be completely invisible, and be on the same actor as the mesh you made!
So just to guide you a bit, you’ll want to get fancy with an array and ForLoops, and creating scene nodes with those loops for the procedural part.
Then once you have that, to get the scene node (point) closest to the mouse, you want “Convert mouse location to world space” and then from THAT location, do a small sphere trace (so you’re doing a sphere trace around the mouse location then) and get all of the output actors and find the one with the smallest difference in distance from the original point!
Well… while you could add “invisible” objects on the grid points and then do a sphere trace at the mouse projected location… I personally would slap myself if I ever did it that way! (lol, no offence)
Best way is to use just good old math.
First you convert the mouse location to world space, then you project the location to a plane (your grid is a plane in this case), you can use the line plane intersection node for this.
Then finally you can use something like the “vector snapped to grid” or “snap to grid (float)” node (along with some clamping if you don’t want to go outside the grid) to snap to nearest grid multiple.
If you need more help with the math, I could cook some example blueprint if you want.