# Modifying the FDragTool\_Measure cpp file

**URL:** <https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 22, 2021, 5:07pm UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025 "2021-07-22T17:07:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_ffb97c02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ffb97c02](https://forums.unrealengine.com/u/anonymous_user_ffb97c02)\
**Post date:** [July 22, 2021, 5:07pm UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025/1 "2021-07-22T17:07:48Z")

</div>

Hello,  
I want to modify the FDragTool\_Measure cpp file that is responsible for measuring distances in the viewport (uisng middle mouse drag)

> **[FDragTool\_Measure](https://docs.unrealengine.com/4.26/en-US/API/Editor/UnrealEd/FDragTool_Measure/)**
>
> Draws a line in the current viewport and displays the distance between its start/end points in the center of it.

 ![UE_C++MeasureTool](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/9/79c3a736be971079569e47217a76facddde70df2.jpeg)

What’s the best way to do this ?

1. Download source , make the edit and rebuild the engine  
or
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,  
b

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [July 25, 2021, 3:02am UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025/2 "2021-07-25T03:02:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ffb97c02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ffb97c02](https://forums.unrealengine.com/u/anonymous_user_ffb97c02)\
**Post date:** [July 26, 2021, 4:00pm UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025/3 "2021-07-26T16:00:06Z")

</div>

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.  
b

---

<div class="post-metadata">

**Author:** ![GeneralTullius](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/generaltullius/32/264919_2.png) [@GeneralTullius](https://forums.unrealengine.com/u/GeneralTullius)\
**Post date:** [August 11, 2021, 1:33pm UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025/4 "2021-08-11T13:33:00Z")

</div>

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”

 ![BeforeUE4](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/4/34efc1b3c9f96db4ab6b67e9f10fb7a704640dd4.png)

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

```auto
UENUM()
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

```auto
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);
			break;

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

	case MeasureUnits_Feets:
			Divisor = 30.48f; 
			// Max one decimal places allowed for Feets.
			DecimalPlaces = FMath::Clamp(FMath::FloorToInt(1.5f - OrderOfMagnitude), 0, 1);
			break;
}

```

1. Build Engine/Editor & you should now see Feets option in the dropdown menu.

 ![AfterUE4](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/d/fd30ed9e5c648a6cb8fa1ecf8752d878681bb4ea.jpeg)

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

Hope this helps!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ffb97c02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ffb97c02](https://forums.unrealengine.com/u/anonymous_user_ffb97c02)\
**Post date:** [August 11, 2021, 4:42pm UTC](https://forums.unrealengine.com/t/modifying-the-fdragtool-measure-cpp-file/242025/5 "2021-08-11T16:42:54Z")

</div>

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 .

[https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Plugins/Experimental/SampleToolsEditorMode/Source/Private/SampleTools/MeasureDistanceSampleTool.cpp](https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Plugins/Experimental/SampleToolsEditorMode/Source/Private/SampleTools/MeasureDistanceSampleTool.cpp)

Cheers,  
b
