I’m looking to write a Blutility that can take either all selected objects (or shortcut buttons for specific classes of objects, like PlayerStart) and then snaps them to the ground the same way the “End” key would.
I’ve written my own using LineTraceForObjects to start, but for PlayerStarts in particular it’s not working in the same manner. It’s actually aligning the origin of the object to the ground (which is what I’m telling it to do, of course) whereas with the End key it actually places the object appropriately above the ground by some amount.
So my questions are:
Can I call the exact implementation of the “End” key in Blueprint?
What method is the “End” key using to determine how far above the ground to put an object?
Where in C++ is the “End” key function defined? (I couldn’t find it)
My first thought for #2 would be to find a collider and take half the height of it, but that’s just a guess - I was hoping for something more substantiated.
EDIT: I’ve had pretty close to identical results using an explicit “92” offset to match the Capsule’s half-height, but doing something more programmatically would be better so it can work with all objects as well as possible.
The “End” key is called “Snap to Floor” in the Editor Preferences.
Maybe search the engine source code project for keyboard shortcuts? Search for the “Snap to Floor” name or for its description: “Snaps the actor or component to the floor below it”.
Making this in Blueprints doesn’t seem very difficult. You create the “End” key (or whatever else) as an action mapping bind from the Project Settings - Engine - Input - Bindings, and if you press it, it moves the object down on the Z axis until it overlaps something, at which point you stop moving it. But not too fast, else it will most likely pass through everything on its way down.
Thanks, “SnapToFloor” gets me to the right spots in the source code. It’s a lot more in-depth than I expected, but I supposed that’s why it works so well compared to the line trace method I’m employing. I’m disappointed a similar “Snap” function isn’t exposed to Blueprint from what I can tell. There’s just SnapToGrid, which is inherently different.
I still think using a Line Trace is the right way to go (rather than moving the object over and over again), but determining the offset is the real challenge. Unreal’s code seems to be grabbing the bounds of the object and using that, so I might give that a go myself.