Snapping to grid doesn't align with FComponentVisualizer::GetWidgetLocation

Hey,

I think this is a bug, I didn’t find any information on this and I couldn’t find a work around. I have some kind of custom spline implementation where you can add and delete points. The points that my code add isn’t aligned with the grid in the level editor (I can’t find how I can get the grid settings from the level editor). When you click a point, I set the WidgetLocation to the exact location. If you then start moving the point by using the widget, the offset remains to the grid and it doesn’t snap to the grid.

As you can see in the screenshot, after moving the point, it still doesn’t align. FComponentVisualizer::HandleInputDelta is being called with the snap distance (in this case, a difference of 50, while the widget position isn’t aligned).

This is quite annoying as the level designers can’t create strait lines easily. I hope I miss something out and this can be done already.

Hey Daxiuz-

The grid is only a visual representation of space rather than a physical location. The snapping distance will always snap to the same distance each time it moves (in this case setting snapping distance to 50 will move 50cm each time). To align the points of the spline as you suggest the easiest solutions would be to either (A) select the point and then manually set the value so that it lands on the grid. Doing this will allow you to drag the point along the grid from there. The other option would be to (B) change the snapping distance down to 10 and move the point to one of the bold lines of the grid (every 10 grid markers is slightly more pronounced). After doing that you can set the snapping distance back to 50 and drag the point along the grid.

Cheers

Is there a way from within a FComponentVisualizer to get the snapping distance? So if I spawn new points I can directly spawn then onto the grid?

Hey Daxiuz-

There is no way to access the snapping distance in that class. If you have a spline that has two points, both of which are aligned to the grid, and you create a third point along the spline is that point on the grid? Or are you referring to picking somewhere along the spline that is not in line with the grid by default and having a new point created on the grid automatically?

Hey ,

When I have a spline along the line, and I add a point the center, then it’s also on the line. But when the spline is not aligned with the grid, the new point will not be on the grid. This is not the default spline, but my own implementation of it.

In the HandleInputDelta function, I have the FEditorViewportClient and FViewport objects. Is there a way to get the scale of the grid from one of those?

After 2 hours of source code searching :slight_smile: I found a way to get the information.

#include "Settings/LevelEditorViewportSettings.h"

// Is enabled: GetDefault<ULevelEditorViewportSettings>()->GridEnabled
// Size in float: GEditor->GetGridSize() (is using also GetDefault<ULevelEditorViewportSettings>)

if (GetDefault<ULevelEditorViewportSettings>()->GridEnabled) {

  Location = Location.GridSnap(GEditor->GetGridSize());

}