r.VSyncEditor

r.VSyncEditor

#Overview

name: r.VSyncEditor

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

It is referenced in 11 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.VSyncEditor is to control vertical synchronization (VSync) in the Unreal Engine editor. This setting variable is primarily related to the rendering system, specifically for managing frame synchronization in the editor environment.

The r.VSyncEditor variable is utilized by the following Unreal Engine subsystems and modules:

  1. Core Engine (ConsoleManager)
  2. UnrealEd (Editor Performance Settings)
  3. SlateRHIRenderer (for rendering Slate UI)
  4. RenderGrid plugin (experimental)

The value of this variable is set in multiple places:

  1. It is initially defined as a console variable in the Core engine.
  2. It can be modified through the Editor Performance Settings in the Unreal Editor.
  3. It may be dynamically changed by certain systems, such as the RenderGrid plugin or Learning Agents Training system.

The r.VSyncEditor variable interacts closely with the bEnableVSync property in the UEditorPerformanceSettings class. They share the same value and are used interchangeably in different parts of the engine.

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

  1. It affects only the editor environment, not the game runtime.
  2. Changing this value can impact editor performance and responsiveness.
  3. It may be automatically adjusted by certain plugins or training systems.

Best practices when using this variable include:

  1. Consider the trade-offs between visual smoothness and potential performance impact when enabling VSync in the editor.
  2. Be cautious when modifying this value programmatically, as it can affect the overall editor experience.
  3. When developing plugins or systems that may need to temporarily disable VSync, ensure to restore the original value when done.

Regarding the associated variable bEnableVSync:

The purpose of bEnableVSync is to provide a user-friendly way to control the VSync setting in the editor through the Editor Performance Settings. It serves the same function as r.VSyncEditor but is exposed as a configuration option in the editor interface.

This variable is primarily used in the UnrealEd module and is also referenced by some experimental plugins like the Learning Agents Training system. The value of bEnableVSync is typically set through the editor interface or configuration files.

Developers should be aware that changes to bEnableVSync will directly affect the r.VSyncEditor console variable. When modifying this value programmatically, it’s important to call PostEditChange() on the UEditorPerformanceSettings object to ensure the changes are properly propagated.

Best practices for using bEnableVSync include:

  1. Use this variable when you need to modify the VSync setting through editor configuration or UI.
  2. Remember to handle both r.VSyncEditor and bEnableVSync when implementing systems that need to temporarily change the VSync behavior in the editor.
  3. Always restore the original value of this setting after temporarily modifying it for specific operations or training scenarios.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3842

Scope: file

Source code excerpt:

#if WITH_EDITOR
static TAutoConsoleVariable<int32> CVarSetVSyncEditorEnabled(
	TEXT("r.VSyncEditor"),
	0,
	TEXT("0: VSync is disabled in editor.(default)\n"
		 "1: VSync is enabled in editor."),
	ECVF_RenderThreadSafe);
#endif

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/Editor/EditorPerformanceSettings.h:58

Scope (from outer to inner):

file
class        class UEditorPerformanceSettings : public UDeveloperSettings

Source code excerpt:

	
	/** Should VSync be enabled in editor? */
	UPROPERTY(EditAnywhere, config, Category=EditorPerformance, meta=(DisplayName="Enable VSync", ConsoleVariable="r.VSyncEditor"))
	uint32 bEnableVSync : 1;

	/** 
	 * By default the editor will adjust scene scaling (quality) for high DPI in order to ensure consistent performance with very large render targets.
	 * Enabling this will disable automatic adjusting and render at the full resolution of the viewport
	 */

#Loc: <Workspace>/Engine/Plugins/Experimental/RenderGrid/Source/RenderGrid/Private/Utils/RenderGridUtils.cpp:429

Scope (from outer to inner):

file
function     FRenderGridPreviousEngineFpsSettings UE::RenderGrid::Private::FRenderGridUtils::DisableFpsLimit

Source code excerpt:

	{
		static IConsoleVariable* VSync = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSync"));
		static IConsoleVariable* VSyncEditor = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSyncEditor"));
		UEditorPerformanceSettings* EditorPerformanceSettings = GetMutableDefault<UEditorPerformanceSettings>();

		Settings.bHasBeenSet = true;
		Settings.bUseFixedFrameRate = GEngine->bUseFixedFrameRate;
		Settings.bForceDisableFrameRateSmoothing = GEngine->bForceDisableFrameRateSmoothing;
		Settings.MaxFps = GEngine->GetMaxFPS();

#Loc: <Workspace>/Engine/Plugins/Experimental/RenderGrid/Source/RenderGrid/Private/Utils/RenderGridUtils.cpp:456

Scope (from outer to inner):

file
function     void UE::RenderGrid::Private::FRenderGridUtils::RestoreFpsLimit

Source code excerpt:

	{
		static IConsoleVariable* VSync = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSync"));
		static IConsoleVariable* VSyncEditor = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSyncEditor"));
		UEditorPerformanceSettings* EditorPerformanceSettings = GetMutableDefault<UEditorPerformanceSettings>();

		GEngine->bUseFixedFrameRate = Settings.bUseFixedFrameRate;
		GEngine->bForceDisableFrameRateSmoothing = Settings.bForceDisableFrameRateSmoothing;
		GEngine->SetMaxFPS(Settings.MaxFps);
		VSync->Set(Settings.bVSync);

#Loc: <Workspace>/Engine/Plugins/Experimental/RenderGrid/Source/RenderGrid/Public/Utils/RenderGridUtils.h:41

Scope (from outer to inner):

file
function     struct RENDERGRID_API FRenderGridPreviousEngineFpsSettings { GENERATED_BODY

Source code excerpt:

	bool bVSync = false;

	/** The previous value of console variable "r.VSyncEditor". */
	UPROPERTY()
	bool bVSyncEditor = false;

	/** The previous value of UEditorPerformanceSettings->bThrottleCPUWhenNotForeground. */
	UPROPERTY()
	bool bThrottleCPUWhenNotForeground = false;

#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:1743

Scope (from outer to inner):

file
function     void FSlateRHIRenderer::DrawWindows_Private

Source code excerpt:

				if (GIsEditor)
				{
					static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSyncEditor"));
					bForceVsyncFromCVar = (CVar->GetInt() != 0);
				}
				else
				{
					static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSync"));
					bForceVsyncFromCVar = (CVar->GetInt() != 0);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningAgentsTraining/Private/LearningAgentsTrainer.cpp:444

Scope (from outer to inner):

file
function     void ULearningAgentsTrainer::BeginTraining

Source code excerpt:

	{
		bUseLessCPUInTheBackground = EditorPerformanceSettings->bThrottleCPUWhenNotForeground;
		bEditorVSyncEnabled = EditorPerformanceSettings->bEnableVSync;
	}
#endif

	// Apply Training GameState Settings

	FApp::SetUseFixedTimeStep(TrainerGameSettings.bUseFixedTimeStep);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningAgentsTraining/Private/LearningAgentsTrainer.cpp:490

Scope (from outer to inner):

file
function     void ULearningAgentsTrainer::BeginTraining

Source code excerpt:

	if (TrainerGameSettings.bDisableEditorVSync && EditorPerformanceSettings)
	{
		EditorPerformanceSettings->bEnableVSync = false;
		EditorPerformanceSettings->PostEditChange();
	}
#endif

	// Start Trainer

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningAgentsTraining/Private/LearningAgentsTrainer.cpp:639

Scope (from outer to inner):

file
function     void ULearningAgentsTrainer::DoneTraining

Source code excerpt:

		{
			EditorPerformanceSettings->bThrottleCPUWhenNotForeground = bUseLessCPUInTheBackground;
			EditorPerformanceSettings->bEnableVSync = bEditorVSyncEnabled;
			EditorPerformanceSettings->PostEditChange();
		}
#endif

		bIsTraining = false;
	}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/Editor/EditorPerformanceSettings.h:59

Scope (from outer to inner):

file
class        class UEditorPerformanceSettings : public UDeveloperSettings

Source code excerpt:

	/** Should VSync be enabled in editor? */
	UPROPERTY(EditAnywhere, config, Category=EditorPerformance, meta=(DisplayName="Enable VSync", ConsoleVariable="r.VSyncEditor"))
	uint32 bEnableVSync : 1;

	/** 
	 * By default the editor will adjust scene scaling (quality) for high DPI in order to ensure consistent performance with very large render targets.
	 * Enabling this will disable automatic adjusting and render at the full resolution of the viewport
	 */
	UPROPERTY(EditAnywhere, config, Category=ViewportResolution, meta=(

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorPerformanceSettings.cpp:44

Scope (from outer to inner):

file
function     void UEditorPerformanceSettings::PostInitProperties

Source code excerpt:

	CVarEditorViewportOverrideGameScreenPercentage->Set(bOverridePIEScreenPercentage != 0, ECVF_SetByProjectSetting);

	if (FProperty* EnableVSyncProperty = GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UEditorPerformanceSettings, bEnableVSync)))
	{
		ExportValuesToConsoleVariables(EnableVSyncProperty);
	}

	UEditorPerformanceProjectSettings::ExportResolutionValuesToConsoleVariables();
}