GridEnabled

GridEnabled

#Overview

name: GridEnabled

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 15 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of GridEnabled is to control whether grid snapping is enabled for positioning actors in the Unreal Engine editor. This setting variable is part of the editor’s viewport and level editing system. Here are the key points about GridEnabled:

  1. It is used by various Unreal Engine subsystems and modules, primarily in the editor, including:

    • GeometryMode plugin
    • GizmoEdMode
    • LevelEditor
    • UnrealEd
    • EditorInteractiveToolsFramework
    • VREditor
    • WorldBrowser
  2. The value of this variable is set in the ULevelEditorViewportSettings class, which is a configuration class for editor viewport settings.

  3. GridEnabled interacts with other variables and systems:

    • It often works in conjunction with RotGridEnabled for rotation snapping.
    • It affects the behavior of the GetGridSize() function.
    • It’s used in conjunction with the current viewport’s grid size.
  4. Developers should be aware that:

    • Changing this setting affects multiple editor tools and functionalities.
    • It impacts actor placement, duplication, and movement in the editor.
    • It’s used in both 2D and 3D contexts within the editor.
  5. Best practices when using this variable include:

    • Use it in conjunction with appropriate grid sizes for your project’s scale.
    • Consider the impact on workflow when enabling or disabling grid snapping.
    • Be aware of its interaction with other snapping settings (like vertex snapping) which may override grid snapping.

GridEnabled is a fundamental setting for editor usability and precision, affecting how developers interact with the scene in the Unreal Engine editor.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEditorPerProjectUserSettings.ini:414, section: [/Script/UnrealEd.LevelEditorViewportSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Editor/GeometryMode/Source/GeometryMode/Private/GeometryModifiers.cpp:1779

Scope (from outer to inner):

file
function     void UGeomModifier_Pen::Tick

Source code excerpt:

		FVector NewMouseWorldSpacePos = ComputeWorldSpaceMousePos(ViewportClient);
		// If the grid is enabled, figure out where the nearest grid location is to the mouse cursor
		if( GetDefault<ULevelEditorViewportSettings>()->GridEnabled )
		{
			NewMouseWorldSpacePos = NewMouseWorldSpacePos.GridSnap( GEditor->GetGridSize() );
		}

		// If the mouse position has moved, update the viewport
		if( NewMouseWorldSpacePos != MouseWorldSpacePos )

#Loc: <Workspace>/Engine/Plugins/Experimental/GizmoEdMode/Source/GizmoEdMode/Private/GizmoEdMode.cpp:96

Scope (from outer to inner):

file
function     void UGizmoEdMode::ModeTick

Source code excerpt:

	if ( LastFactory )
	{
		LastFactory->ConfigureGridSnapping(GetDefault<ULevelEditorViewportSettings>()->GridEnabled,
		                                   GetDefault<ULevelEditorViewportSettings>()->RotGridEnabled, InteractiveGizmos);
	}
}

#undef LOCTEXT_NAMESPACE

#Loc: <Workspace>/Engine/Source/Editor/Experimental/EditorInteractiveToolsFramework/Private/EdModeInteractiveToolsContext.cpp:164

Scope (from outer to inner):

file
class        class FEdModeToolsContextQueriesImpl : public IToolsContextQueriesAPI
function     virtual FToolContextSnappingConfiguration GetCurrentSnappingSettings

Source code excerpt:

	{
		FToolContextSnappingConfiguration Config;
		Config.bEnablePositionGridSnapping = (GetDefault<ULevelEditorViewportSettings>()->GridEnabled != 0);
		float EditorGridSize = GEditor->GetGridSize();
		Config.PositionGridDimensions = FVector(EditorGridSize, EditorGridSize, EditorGridSize);
		Config.bEnableRotationGridSnapping = (GetDefault<ULevelEditorViewportSettings>()->RotGridEnabled != 0);
		Config.RotationGridAngles = GEditor->GetRotGridSize();
		Config.bEnableAbsoluteWorldSnapping = ToolsContext->GetAbsoluteWorldSnappingEnabled();
		return Config;

#Loc: <Workspace>/Engine/Source/Editor/LevelEditor/Private/LevelEditorActions.cpp:2175

Scope (from outer to inner):

file
function     void FLevelEditorActionCallbacks::LocationGridSnap_Clicked

Source code excerpt:

void FLevelEditorActionCallbacks::LocationGridSnap_Clicked()
{
	GUnrealEd->Exec( GetWorld(), *FString::Printf( TEXT("MODE GRID=%d"), !GetDefault<ULevelEditorViewportSettings>()->GridEnabled ? 1 : 0 ) );	
}


bool FLevelEditorActionCallbacks::LocationGridSnap_IsChecked()
{
	return GetDefault<ULevelEditorViewportSettings>()->GridEnabled;
}


void FLevelEditorActionCallbacks::RotationGridSnap_Clicked()
{
	GUnrealEd->Exec( GetWorld(), *FString::Printf( TEXT("MODE ROTGRID=%d"), !GetDefault<ULevelEditorViewportSettings>()->RotGridEnabled ? 1 : 0 ) );

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/Settings/LevelEditorViewportSettings.h:429

Scope (from outer to inner):

file
class        class ULevelEditorViewportSettings : public UObject

Source code excerpt:

	/** If enabled, actor positions will snap to the grid. */
	UPROPERTY(EditAnywhere, config, Category=GridSnapping, meta=(DisplayName = "Enable Grid Snapping"))
	uint32 GridEnabled:1;
	
	/** If enabled, actor rotations will snap to the grid. */
	UPROPERTY(EditAnywhere, config, Category=GridSnapping, meta=(DisplayName = "Enable Rotation Snapping"))
	uint32 RotGridEnabled:1;

	/** If enabled, actor sizes will snap to the grid. */

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorComponents.cpp:173

Scope (from outer to inner):

file
function     void FGridWidget::DrawNewGrid

Source code excerpt:


	// not used yet
	const bool bSnapEnabled = GetDefault<ULevelEditorViewportSettings>()->GridEnabled;

	float SnapAlphaMultiplier = 1.0f;

	// to get a light grid in a black level but use a high opacity value to be able to see it in a bright level
	static float Darken = 0.11f;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorConstraints.cpp:38

Scope (from outer to inner):

file
function     void UEditorEngine::SetGridSize

Source code excerpt:

	ViewportSettings->PostEditChange();

	FEditorDelegates::OnGridSnappingChanged.Broadcast(GetDefault<ULevelEditorViewportSettings>()->GridEnabled, GetGridSize());
	
	RedrawLevelEditingViewports();
	FEditorSupportDelegates::UpdateUI.Broadcast();
}

void UEditorEngine::GridSizeIncrement( )

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorConstraints.cpp:166

Scope (from outer to inner):

file
function     FVector UEditorEngine::GetGridLocationOffset

Source code excerpt:

FVector UEditorEngine::GetGridLocationOffset(bool bUniformOffset) const
{
	const float Offset = GetDefault<ULevelEditorViewportSettings>()->GridEnabled ? GetGridSize() : 0.0f;

	FVector LocationOffset(Offset, Offset, Offset);
	if (!bUniformOffset && GCurrentLevelEditingViewportClient)
	{
		switch (GCurrentLevelEditingViewportClient->ViewportType)
		{

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/STransformViewportToolbar.cpp:978

Scope (from outer to inner):

file
function     ECheckBoxState STransformViewportToolBar::IsLocationGridSnapChecked

Source code excerpt:

ECheckBoxState STransformViewportToolBar::IsLocationGridSnapChecked() const
{
	return GetDefault<ULevelEditorViewportSettings>()->GridEnabled ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}

ECheckBoxState STransformViewportToolBar::IsRotationGridSnapChecked() const
{
	return GetDefault<ULevelEditorViewportSettings>()->RotGridEnabled ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/STransformViewportToolbar.cpp:1007

Scope (from outer to inner):

file
function     void STransformViewportToolBar::HandleToggleLocationGridSnap

Source code excerpt:

void STransformViewportToolBar::HandleToggleLocationGridSnap( ECheckBoxState InState )
{
	GUnrealEd->Exec( GEditor->GetEditorWorldContext().World(), *FString::Printf( TEXT("MODE GRID=%d"), !GetDefault<ULevelEditorViewportSettings>()->GridEnabled ? 1 : 0 ) );
}

void STransformViewportToolBar::HandleToggleRotationGridSnap(ECheckBoxState InState)
{
	GUnrealEd->Exec(GEditor->GetEditorWorldContext().World(), *FString::Printf(TEXT("MODE ROTGRID=%d"), !GetDefault<ULevelEditorViewportSettings>()->RotGridEnabled ? 1 : 0));
}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/SnappingUtils.cpp:110

Scope (from outer to inner):

file
function     bool FEditorViewportSnapping::IsSnapToGridEnabled

Source code excerpt:

bool FEditorViewportSnapping::IsSnapToGridEnabled()
{
	return GetDefault<ULevelEditorViewportSettings>()->GridEnabled && !IsSnapToVertexEnabled();
}

bool FEditorViewportSnapping::IsSnapRotationEnabled()
{	
	// Ask Current Editor Mode if Rotation Snap is enabled
	return GLevelEditorModeTools().IsSnapRotationEnabled();

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Subsystems/EditorActorSubsystem.cpp:258

Scope (from outer to inner):

file
function     void UEditorActorSubsystem::DuplicateSelectedActors

Source code excerpt:

	// duplicate selected
	ABrush::SetSuppressBSPRegeneration(true);
	GEditor->edactDuplicateSelected(InWorld->GetCurrentLevel(), GetDefault<ULevelEditorViewportSettings>()->GridEnabled);
	ABrush::SetSuppressBSPRegeneration(false);

	// Find out if any of the selected actors will change the BSP.
	// and only then rebuild BSP as this is expensive. 
	const FSelectedActorInfo& SelectedActors = AssetSelectionUtils::GetSelectedActorInfo();
	if (SelectedActors.bHaveBrush)

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/UnrealEdSrv.cpp:3024

Scope (from outer to inner):

file
function     bool UUnrealEdEngine::Exec_Mode

Source code excerpt:


		ULevelEditorViewportSettings* ViewportSettings = GetMutableDefault<ULevelEditorViewportSettings>();
		ViewportSettings->GridEnabled = DWord1;
		ViewportSettings->PostEditChange();

		FEditorDelegates::OnGridSnappingChanged.Broadcast(ViewportSettings->GridEnabled, GetGridSize());
		FEditorSupportDelegates::UpdateUI.Broadcast();
	}

	if( FParse::Value(Str, TEXT("ROTGRID="), DWord1) )
	{
		FinishAllSnaps();

#Loc: <Workspace>/Engine/Source/Editor/VREditor/Private/VREditorActions.cpp:46

Scope (from outer to inner):

file
function     ECheckBoxState FVREditorActionCallbacks::GetTranslationSnapState

Source code excerpt:

ECheckBoxState FVREditorActionCallbacks::GetTranslationSnapState()
{
	return GetDefault<ULevelEditorViewportSettings>()->GridEnabled ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}

void FVREditorActionCallbacks::OnTranslationSnapSizeButtonClicked()
{
	const TArray<float>& GridSizes = GEditor->GetCurrentPositionGridArray();
	const int32 CurrentGridSize = GetDefault<ULevelEditorViewportSettings>()->CurrentPosGridSize;

#Loc: <Workspace>/Engine/Source/Editor/WorldBrowser/Private/Tiles/SWorldComposition.cpp:864

Scope (from outer to inner):

file
class        class SWorldCompositionGrid : public SNodePanel
function     void MoveSelectedNodes

Source code excerpt:

				SnappingDistanceWorld = BoundsSnappingDistance/GetZoomAmount();
			}
			else if (GetDefault<ULevelEditorViewportSettings>()->GridEnabled)
			{
				SnappingDistanceWorld = GEditor->GetGridSize();
			}
		
			FVector2D StartPosition = ItemDragged->GetPosition() - ItemDragged->GetLevelModel()->GetLevelTranslationDelta();
			FVector2D AbsoluteDelta = NewPosition - StartPosition;