r.ScreenshotDelegate

r.ScreenshotDelegate

#Overview

name: r.ScreenshotDelegate

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.ScreenshotDelegate is to control the behavior of screenshot delegates in Unreal Engine. It is primarily used in the rendering system, specifically for managing screenshot capture and processing.

This setting variable is primarily used in the Engine module, particularly within the GameViewportClient class. Based on the callsites, it’s clear that this variable directly affects the screenshot capturing process.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, which means screenshot delegates are enabled by default.

The r.ScreenshotDelegate variable interacts closely with its associated variable CVarScreenshotDelegate. They share the same value and are used interchangeably in the code.

Developers must be aware that disabling this variable (setting it to 0) will prevent the processing of incoming screenshot requests and may break some features. This setting was introduced as a temporary solution to address issues with screenshot delegates.

Best practices when using this variable include:

  1. Keep it enabled (set to 1) unless you’re experiencing specific issues related to screenshot capturing.
  2. If you need to disable it, be aware that it may affect other screenshot-related functionality in your project.
  3. Consider this variable as a temporary solution and look for more permanent fixes if you’re experiencing issues with screenshot delegates.

Regarding the associated variable CVarScreenshotDelegate:

The purpose of CVarScreenshotDelegate is to provide a programmatic way to access and modify the r.ScreenshotDelegate setting within C++ code. It’s implemented as a TAutoConsoleVariable, which allows it to be easily accessed and modified at runtime.

This variable is used in the Engine module, specifically within the GameViewportClient class, to determine whether screenshot delegates should be processed.

The value of CVarScreenshotDelegate is set through the console variable system, initialized with the same default value as r.ScreenshotDelegate (1).

CVarScreenshotDelegate interacts directly with r.ScreenshotDelegate, as they represent the same setting.

Developers should be aware that changes to CVarScreenshotDelegate will affect the behavior of screenshot capturing in the engine. It’s used in conditional statements to determine whether to process screenshot delegates.

Best practices for using CVarScreenshotDelegate include:

  1. Use GetValueOnGameThread() when accessing its value in game thread code.
  2. Be cautious when modifying its value, as it can have wide-ranging effects on screenshot functionality.
  3. Consider using this variable for debugging or temporary fixes, but aim for more permanent solutions for screenshot-related issues.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp:100

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarScreenshotDelegate(
	TEXT("r.ScreenshotDelegate"),
	1,
	TEXT("ScreenshotDelegates prevent processing of incoming screenshot request and break some features. This allows to disable them.\n")
	TEXT("Ideally we rework the delegate code to not make that needed.\n")
	TEXT(" 0: off\n")
	TEXT(" 1: delegates are on (default)"),
	ECVF_Default);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp:99

Scope: file

Source code excerpt:

	ECVF_Default);

static TAutoConsoleVariable<int32> CVarScreenshotDelegate(
	TEXT("r.ScreenshotDelegate"),
	1,
	TEXT("ScreenshotDelegates prevent processing of incoming screenshot request and break some features. This allows to disable them.\n")
	TEXT("Ideally we rework the delegate code to not make that needed.\n")
	TEXT(" 0: off\n")
	TEXT(" 1: delegates are on (default)"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp:2172

Scope (from outer to inner):

file
function     bool UGameViewportClient::ProcessScreenShots

Source code excerpt:

			if (Bitmap.Num() > 0)
			{
				if (ScreenshotCapturedDelegate.IsBound() && CVarScreenshotDelegate.GetValueOnGameThread())
				{
					// Ensure that all pixels' alpha is set to 255
					for (auto& Color : Bitmap)
					{
						Color.A = 255;
					}