r.Water.WaterMesh.Enabled

r.Water.WaterMesh.Enabled

#Overview

name: r.Water.WaterMesh.Enabled

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 r.Water.WaterMesh.Enabled is to control whether the water mesh is enabled or disabled in Unreal Engine 5. This setting affects both the rendering and the water tile generation in the water system.

This setting variable is primarily used in the Water plugin, which is part of the experimental features in Unreal Engine 5. The main subsystems and modules that rely on this variable are:

  1. WaterMeshComponent
  2. WaterSubsystem
  3. WaterUtils

The value of this variable is set through the console variable system in Unreal Engine. It is initialized with a default value of 1 (enabled) in the WaterMeshComponent.cpp file.

This variable interacts closely with several other variables, particularly:

  1. CVarWaterEnabled
  2. CVarWaterMeshEnableRendering

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

  1. It affects both rendering and water tile generation.
  2. Changes to this variable will trigger a callback in the WaterSubsystem.
  3. It works in conjunction with other water-related variables to determine the overall state of the water system.

Best practices when using this variable include:

  1. Use it in combination with other water-related variables for fine-grained control.
  2. Be mindful of performance implications when enabling/disabling the water mesh.
  3. Use the FWaterUtils::IsWaterMeshEnabled() function to check the current state, as it considers both this variable and the overall water system state.

Regarding the associated variable CVarWaterMeshEnabled:

The purpose of CVarWaterMeshEnabled is to provide a programmatic interface to the r.Water.WaterMesh.Enabled console variable. It allows C++ code to directly interact with the setting.

This variable is used throughout the Water plugin’s code to check the enabled state of the water mesh. It’s particularly important in the WaterSubsystem and WaterUtils modules.

The value of CVarWaterMeshEnabled is set when the r.Water.WaterMesh.Enabled console variable is modified.

CVarWaterMeshEnabled interacts closely with CVarWaterEnabled and CVarWaterMeshEnableRendering to determine the overall state of the water system.

Developers should be aware that this variable is used in both game and render threads, and appropriate thread-safe access methods should be used (GetValueOnGameThread() or GetValueOnRenderThread()).

Best practices for using CVarWaterMeshEnabled include:

  1. Use the appropriate thread-safe accessor methods.
  2. Consider using the FWaterUtils helper functions instead of directly accessing the variable.
  3. Be aware of the performance implications of frequently checking or changing this variable’s value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterMeshComponent.cpp:57

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarWaterMeshEnabled(
	TEXT("r.Water.WaterMesh.Enabled"),
	1,
	TEXT("If the water mesh is enabled or disabled. This affects both rendering and the water tile generation"),
	ECVF_RenderThreadSafe
);

TAutoConsoleVariable<int32> CVarWaterMeshMIDDeduplication(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterMeshComponent.cpp:56

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> CVarWaterMeshEnabled(
	TEXT("r.Water.WaterMesh.Enabled"),
	1,
	TEXT("If the water mesh is enabled or disabled. This affects both rendering and the water tile generation"),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterSubsystem.cpp:115

Scope: file

Source code excerpt:

);

extern TAutoConsoleVariable<int32> CVarWaterMeshEnabled;
extern TAutoConsoleVariable<int32> CVarWaterMeshEnableRendering;


// ----------------------------------------------------------------------------------

#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterSubsystem.cpp:263

Scope (from outer to inner):

file
function     void UWaterSubsystem::Initialize

Source code excerpt:

	FConsoleVariableDelegate NotifyWaterVisibilityChanged = FConsoleVariableDelegate::CreateUObject(this, &UWaterSubsystem::NotifyWaterVisibilityChangedInternal);
	CVarWaterEnabled->SetOnChangedCallback(NotifyWaterVisibilityChanged);
	CVarWaterMeshEnabled->SetOnChangedCallback(NotifyWaterVisibilityChanged);
	CVarWaterMeshEnableRendering->SetOnChangedCallback(NotifyWaterVisibilityChanged);

#if WITH_EDITOR
	GetDefault<UWaterRuntimeSettings>()->OnSettingsChange.AddUObject(this, &UWaterSubsystem::ApplyRuntimeSettings);
#endif //WITH_EDITOR
	ApplyRuntimeSettings(GetDefault<UWaterRuntimeSettings>(), EPropertyChangeType::ValueSet);

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterSubsystem.cpp:325

Scope (from outer to inner):

file
function     void UWaterSubsystem::Deinitialize

Source code excerpt:

	CVarShallowWaterSim->SetOnChangedCallback(NullCallback);
	CVarWaterEnabled->SetOnChangedCallback(NullCallback);
	CVarWaterMeshEnabled->SetOnChangedCallback(NullCallback);
	CVarWaterMeshEnableRendering->SetOnChangedCallback(NullCallback);

	World->OnBeginPostProcessSettings.RemoveAll(this);
	World->RemovePostProcessVolume(&UnderwaterPostProcessVolume);

	GetWaterBodyManagerInternal().Deinitialize();

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterUtils.cpp:7

Scope: file

Source code excerpt:


extern TAutoConsoleVariable<int32> CVarWaterEnabled;
extern TAutoConsoleVariable<int32> CVarWaterMeshEnabled;
extern TAutoConsoleVariable<int32> CVarWaterMeshEnableRendering;

static TAutoConsoleVariable<float> CVarWaterMaxFlowVelocity(
	TEXT("r.Water.MaxFlowVelocity"),
	1024.0f,
	TEXT("The maximum magnitude for the velocity of a river to encode in the WaterInfo texture"),

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterUtils.cpp:112

Scope (from outer to inner):

file
function     bool FWaterUtils::IsWaterMeshEnabled

Source code excerpt:

bool FWaterUtils::IsWaterMeshEnabled(bool bIsRenderThread)
{
	return IsWaterEnabled(bIsRenderThread) && !!(bIsRenderThread ? CVarWaterMeshEnabled.GetValueOnRenderThread() : CVarWaterMeshEnabled.GetValueOnGameThread());
}

bool FWaterUtils::IsWaterMeshRenderingEnabled(bool bIsRenderThread)
{
	return IsWaterMeshEnabled(bIsRenderThread) && !!(bIsRenderThread ? CVarWaterMeshEnableRendering.GetValueOnRenderThread() : CVarWaterMeshEnableRendering.GetValueOnGameThread());
}