Modifying the FDragTool_Measure cpp file

I want to modify the FDragTool_Measure cpp file that is responsible for measuring distances in the viewport (uisng middle mouse drag)

What’s the best way to do this ?

  1. Download source , make the edit and rebuild the engine
  2. make a new UE c++ project, create a class , open vs studio and modify the engine cpp file from there and build the solution (this isnt working for me )

Thanking you,

If you’re trying to make changes to the engine, you’ll need the full source build.

1 Like

Yes it worked that way for me.
Is there an alternate way I can do this so I dont have to maintain a different engine build (outside of the one that ships with the Epic launcher) ?

Is rebuilding the engine the only way I can modify the functionality. Cant i derive a plugin from the particular cpp files and then have that over ride engine functionality .

Building the engine from source every time i experiment to make changes is such a time sink.

Thanks for your help though.

Hi ,

I think the easiest way to do this is to add an option in the editor once. In your case, as I understand, you want to use “Feets” instead of default centimeters ( or other options such as meters/kilometers) for Measure Tool. Here’s how I would do it and am sure there could be better ways for doing the same thing. These settings can be accessed from “Editor Preferences”

We need to add option in this dropdown menu so that it can be easily tweaked as and when needed. To do this:

  1. In LevelEditorViewportSettings.h
enum EMeasuringToolUnits
	MeasureUnits_Centimeters UMETA(DisplayName="Centimeters"),
	MeasureUnits_Meters      UMETA(DisplayName="Meters"),
	MeasureUnits_Kilometers  UMETA(DisplayName="Kilometers"),
	MeasureUnits_Feets	     UMETA(DisplayName="Feets")
  1. In DragTool_Measure.cpp file, Render() function, add one more switch check for feet & respective calculations for the same
switch (GetDefault<ULevelEditorViewportSettings>()->MeasuringToolUnits)
	case MeasureUnits_Meters:
			Divisor = 100.0f;
			// Max one decimal place allowed for meters.
			DecimalPlaces = FMath::Clamp(FMath::FloorToInt(1.5f - OrderOfMagnitude), 0, 1);

	case MeasureUnits_Kilometers:
			Divisor = 100000.0f;
			// Max two decimal places allowed for kilometers.
			DecimalPlaces = FMath::Clamp(FMath::FloorToInt(4.5f - OrderOfMagnitude), 0, 2);

	case MeasureUnits_Feets:
			Divisor = 30.48f; 
			// Max one decimal places allowed for Feets.
			DecimalPlaces = FMath::Clamp(FMath::FloorToInt(1.5f - OrderOfMagnitude), 0, 1);
  1. Build Engine/Editor & you should now see Feets option in the dropdown menu.

Once selected, this should now also be usable in editor with feet as unit.

Hope this helps!

1 Like

Thank you Rupesh.
That’s such a nice way to do it.

I wish someone would deconstruct how this can be extended into a plugin for educational purposes.
UE even have this implemented as experimental plugins .