TypedElements.EnableViewportSMInstanceSelection

TypedElements.EnableViewportSMInstanceSelection

#Overview

name: TypedElements.EnableViewportSMInstanceSelection

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of TypedElements.EnableViewportSMInstanceSelection is to enable or disable direct selection of Instanced Static Mesh Component (ISMC) Instances in the Level Editor Viewport. This setting is primarily used for the editing and selection system in the Unreal Engine editor.

This setting variable is relied upon by the following Unreal Engine subsystems and modules:

  1. The Level Editor, as evident from its declaration in the ULevelEditorProjectSettings class.
  2. The Instanced Static Mesh Component system, as seen in the InstancedStaticMesh.cpp file.
  3. The Modeling Tools Editor Mode plugin, which uses this variable to create a toggle option in the editor UI.

The value of this variable is set in multiple places:

  1. It is initialized to true in the ULevelEditorProjectSettings constructor.
  2. It can be modified through the editor project settings UI, as it is declared as an UPROPERTY with EditAnywhere and config specifiers.
  3. It can be changed at runtime through the console variable system.

The associated variable bEnableViewportSMInstanceSelection interacts directly with this console variable. They share the same value, and changes to one will affect the other.

Developers should be aware of the following when using this variable:

  1. It affects the behavior of instance selection in the viewport, which can impact user interaction and performance.
  2. Changes to this setting can be made both through the project settings and at runtime via console commands.
  3. The setting is used in conjunction with the TypedElements system, which is part of Unreal Engine’s selection and interaction framework.

Best practices when using this variable include:

  1. Consider the performance implications of enabling instance selection, especially for scenes with many instanced static meshes.
  2. Ensure that any code relying on instance selection checks this variable’s value before proceeding.
  3. Use the associated project setting (bEnableViewportSMInstanceSelection) for persistent configuration, and the console variable for runtime toggling or debugging.

Regarding the associated variable bEnableViewportSMInstanceSelection:

This boolean variable is a member of the ULevelEditorProjectSettings class and serves as the project setting counterpart to the console variable. It is initialized to true by default and can be modified through the editor’s project settings. The PostInitProperties() function ensures that the console variable is updated with this setting’s value when the project loads. Any changes to this setting through the editor will also update the console variable, maintaining synchronization between the two.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Public/Settings/EditorProjectSettings.h:205

Scope (from outer to inner):

file
class        class ULevelEditorProjectSettings : public UDeveloperSettings

Source code excerpt:

	UPROPERTY(EditAnywhere, config, Category=Editing, meta=(
		DisplayName="Enable viewport static mesh instance selection",
		ConsoleVariable="TypedElements.EnableViewportSMInstanceSelection"))
	bool bEnableViewportSMInstanceSelection;

public:
	UNREALED_API ULevelEditorProjectSettings(const class FObjectInitializer& ObjectInitializer);
	// UObject interface
	UNREALED_API virtual void PostInitProperties() override;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:169

Scope: file

Source code excerpt:

#if WITH_EDITOR
static TAutoConsoleVariable<int32> CVarEnableViewportSMInstanceSelection(
	TEXT("TypedElements.EnableViewportSMInstanceSelection"),
	1,
	TEXT("Enable direct selection of Instanced Static Mesh Component (ISMC) Instances in the Level Editor Viewport")
);
#endif

static TAutoConsoleVariable<int32> CVarISMForceRemoveAtSwap(

#Loc: <Workspace>/Engine/Plugins/Editor/ModelingToolsEditorMode/Source/ModelingToolsEditorMode/Private/ModelingModeToolkit_Toolbars.cpp:162

Scope (from outer to inner):

file
namespace    UELocal
function     void MakeSubMenu_ModeToggles
lambda-function

Source code excerpt:

		FExecuteAction::CreateLambda([]
		{
			IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("TypedElements.EnableViewportSMInstanceSelection")); 
			int32 CurValue = CVar->GetInt();
			CVar->Set(CurValue == 0 ? 1 : 0);
		}),
		FCanExecuteAction(),
		FIsActionChecked::CreateLambda([]()
		{
			IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("TypedElements.EnableViewportSMInstanceSelection"));
			return (CVar->GetInt() == 1);
		}));

	MenuBuilder.AddMenuEntry(
		LOCTEXT("ToggleInstancesSelection", "Instance Selection"), 
		LOCTEXT("ToggleInstancesSelection_Tooltip", "Enable/Disable support for direct selection of InstancedStaticMeshComponent Instances (via TypedElements.EnableViewportInstanceSelection cvar)"),

#Associated Variable and Callsites

This variable is associated with another variable named bEnableViewportSMInstanceSelection. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/EditorProjectSettings.cpp:212

Scope (from outer to inner):

file
function     ULevelEditorProjectSettings::ULevelEditorProjectSettings

Source code excerpt:

ULevelEditorProjectSettings::ULevelEditorProjectSettings( const FObjectInitializer& ObjectInitializer )
	: Super(ObjectInitializer)
	, bEnableViewportSMInstanceSelection(true)
{
}

void ULevelEditorProjectSettings::PostInitProperties()
{
	Super::PostInitProperties();
	if (FProperty* EnableSMInstanceSelectionProperty = GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(ULevelEditorProjectSettings, bEnableViewportSMInstanceSelection)))
	{
		ExportValuesToConsoleVariables(EnableSMInstanceSelectionProperty);
	}
}

void ULevelEditorProjectSettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Public/Settings/EditorProjectSettings.h:206

Scope (from outer to inner):

file
class        class ULevelEditorProjectSettings : public UDeveloperSettings

Source code excerpt:

		DisplayName="Enable viewport static mesh instance selection",
		ConsoleVariable="TypedElements.EnableViewportSMInstanceSelection"))
	bool bEnableViewportSMInstanceSelection;

public:
	UNREALED_API ULevelEditorProjectSettings(const class FObjectInitializer& ObjectInitializer);
	// UObject interface
	UNREALED_API virtual void PostInitProperties() override;
	UNREALED_API virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:168

Scope: file

Source code excerpt:


#if WITH_EDITOR
static TAutoConsoleVariable<int32> CVarEnableViewportSMInstanceSelection(
	TEXT("TypedElements.EnableViewportSMInstanceSelection"),
	1,
	TEXT("Enable direct selection of Instanced Static Mesh Component (ISMC) Instances in the Level Editor Viewport")
);
#endif

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:347

Scope (from outer to inner):

file
function     FTypedElementHandle HInstancedStaticMeshInstance::GetElementHandle

Source code excerpt:

	if (Component)
	{
		if (CVarEnableViewportSMInstanceSelection.GetValueOnAnyThread() != 0)
		{
			// Prefer per-instance selection if available
			// This may fail to return a handle if the feature is disabled, or if per-instance editing is disabled for this component
			if (FTypedElementHandle ElementHandle = UEngineElementsLibrary::AcquireEditorSMInstanceElementHandle(Component, InstanceIndex))
			{
				return ElementHandle;