Apologies, there are similar questions to this, elsewhere; but, after 3 fruitless days of searching, I am stuck (and desperate).
Scenario: In the Editor, I want to place an arbitrary number of StaticMeshes on a Landscape; using preferably Python (or C++ if necessary, but I do want to make the facility more accessible than C++). I know the x,y of where I want to place each StaticMesh, but not the z of the landscape (at that x,y). Manually I would use the UI to place a StaticMesh above the Landscape (with the correct x,y) and use the End key, which invokes a SnapToFloor operation. Manually doing this is not an option, as there will be a lot of such objects to be placed (and this operation will be performed many times). I do not know how to achieve this apparently trivial, commonplace requirement. I have discounted raycasting (or line tracing), as this appears to be a runtime only operation. My favoured strategy is to spawn the StaticMesh Actors with the correct x,y and a z value just higher than the highest z of the landscape (which I know) and then (somehow) programmatically invoke SnapToFloor on each of the StaticMesh Actors. An alternative strategy would be if I could easily determine the z of a Landscape surface at some arbitrary x,y. But, I’ve also had very little luck in this direction.
After extensive Googling and reading of API documents, I resorted to examining the UE4 source code, but without much success. I think that I have found where this happens in LevelEditorActions.cpp. Following the code leads to a UEditorEngine.cpp method: SnapObjectTo(args). But, I have no idea how to get a reference to (presumably) the one instance of this, from Python (or C++) code.
I would really appreciate some help please. I am sure that I am not alone in wanting this. Thank-you, in anticipation.
PS I am aware that the landscape will not be flat, where each StaticMesh lands on the floor, but I have a solution for this.
Additional Keywords: SnapToFloor SnapToFloor_Clicked SnapTo_Clicked SnapObjectTo GEditor