r.Water.DebugBuoyancy

r.Water.DebugBuoyancy

#Overview

name: r.Water.DebugBuoyancy

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

It is referenced in 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Water.DebugBuoyancy is to enable debug drawing for water interactions in Unreal Engine 5. This setting variable is primarily used for debugging and visualizing the water buoyancy system.

This setting variable is utilized by the Water plugin, specifically within the Buoyancy component of the water system. The main files that reference this variable are located in the Water plugin’s runtime source code.

The value of this variable is set as a console variable (CVar) with an initial value of 0, which means it’s disabled by default. It can be toggled on or off through the console or by modifying the engine configuration.

The associated variable CVarWaterDebugBuoyancy interacts directly with r.Water.DebugBuoyancy, as they share the same value. This variable is used throughout the code to check if debug drawing should be enabled.

Developers should be aware that this variable is primarily intended for debugging purposes. Enabling it may impact performance, especially in complex water scenes, so it should be used judiciously during development and disabled for release builds.

Best practices when using this variable include:

  1. Use it temporarily during development to visualize and debug water interactions.
  2. Disable it in release builds to avoid unnecessary performance overhead.
  3. Combine it with other debug variables like r.Water.BuoyancyDebugPoints and r.Water.BuoyancyDebugSize for more comprehensive debugging.

Regarding the associated variable CVarWaterDebugBuoyancy:

The purpose of CVarWaterDebugBuoyancy is to provide a programmatic way to access the r.Water.DebugBuoyancy setting within the C++ code. It’s used to check if debug drawing should be enabled in various parts of the water buoyancy simulation.

This variable is used in the Water plugin, specifically in the BuoyancyComponent and BuoyancyComponentSimulation classes.

The value of CVarWaterDebugBuoyancy is set when the r.Water.DebugBuoyancy console variable is initialized. It’s typically accessed using the GetValueOnAnyThread() method.

CVarWaterDebugBuoyancy interacts closely with other debug-related variables like CVarWaterBuoyancyDebugPoints and CVarWaterBuoyancyDebugSize to control various aspects of the debug visualization.

Developers should be aware that this variable is used in conjunction with ENABLE_DRAW_DEBUG preprocessor definitions, so debug drawing will only occur when both the CVar is enabled and debug drawing is compiled into the build.

Best practices for using CVarWaterDebugBuoyancy include:

  1. Use it in conditional statements to wrap debug drawing code.
  2. Ensure it’s only used in development or debug builds to prevent any performance impact in release versions.
  3. Consider exposing it through a user interface for easier toggling during development and testing.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarWaterDebugBuoyancy(
	TEXT("r.Water.DebugBuoyancy"),
	0,
	TEXT("Enable debug drawing for water interactions."),
	ECVF_Default);

TAutoConsoleVariable<int32> CVarWaterBuoyancyDebugPoints(
	TEXT("r.Water.BuoyancyDebugPoints"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

#include UE_INLINE_GENERATED_CPP_BY_NAME(BuoyancyComponent)

TAutoConsoleVariable<int32> CVarWaterDebugBuoyancy(
	TEXT("r.Water.DebugBuoyancy"),
	0,
	TEXT("Enable debug drawing for water interactions."),
	ECVF_Default);

TAutoConsoleVariable<int32> CVarWaterBuoyancyDebugPoints(

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

Scope (from outer to inner):

file
function     void UBuoyancyComponent::ComputeBuoyancy
lambda-function

Source code excerpt:


#if ENABLE_DRAW_DEBUG
		if (CVarWaterDebugBuoyancy.GetValueOnAnyThread())
		{
			const FVector WaterPoint = FVector(CenterLocation.X, CenterLocation.Y, CurrentWaterLevel);
			DrawDebugLine(GetWorld(), WaterPoint - 50.f * FVector::ForwardVector, WaterPoint + 50.f * FVector::ForwardVector, FColor::Blue, false, -1.f, 0, 3.f);
			DrawDebugLine(GetWorld(), WaterPoint - 50.f * FVector::RightVector, WaterPoint + 50.f * FVector::RightVector, FColor::Blue, false, -1.f, 0, 3.f);
		}
#endif

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

Scope (from outer to inner):

file
function     int32 UBuoyancyComponent::UpdatePontoons

Source code excerpt:


#if ENABLE_DRAW_DEBUG
				if (CVarWaterDebugBuoyancy.GetValueOnAnyThread())
				{
					DrawDebugSphere(GetWorld(), Pontoon.CenterLocation, Pontoon.Radius, 16, FColor::Red, false, -1.f, 0, 1.f);
				}
#endif
				ComputeBuoyancy(Pontoon, ForwardSpeedKmh);

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

Scope (from outer to inner):

file
function     int32 UBuoyancyComponent::UpdatePontoons

Source code excerpt:


#if ENABLE_DRAW_DEBUG
		if (CVarWaterDebugBuoyancy.GetValueOnAnyThread())
		{
			const float NumPoints = CVarWaterBuoyancyDebugPoints.GetValueOnAnyThread();
			const float Size = CVarWaterBuoyancyDebugSize.GetValueOnAnyThread();
			const float StartOffset = NumPoints * 0.5f;
			const float Scale = Size / NumPoints;
			TMap<const UWaterBodyComponent*, float> DebugSplineKeyMap;

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Public/BuoyancyComponentSimulation.h:317

Scope (from outer to inner):

file
class        class FBuoyancyComponentSim
function     static void ComputeBuoyancy
lambda-function

Source code excerpt:


			//#if ENABLE_DRAW_DEBUG
			//			if (CVarWaterDebugBuoyancy.GetValueOnAnyThread())
			//			{
			//				const FVector WaterPoint = FVector(CenterLocation.X, CenterLocation.Y, CurrentWaterLevel);
			//				DrawDebugLine(GetWorld(), WaterPoint - 50.f * FVector::ForwardVector, WaterPoint + 50.f * FVector::ForwardVector, FColor::Blue, false, -1.f, 0, 3.f);
			//				DrawDebugLine(GetWorld(), WaterPoint - 50.f * FVector::RightVector, WaterPoint + 50.f * FVector::RightVector, FColor::Blue, false, -1.f, 0, 3.f);
			//			}
			//#endif

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Public/BuoyancyComponentSimulation.h:432

Scope (from outer to inner):

file
class        class FBuoyancyComponentSim
function     static void UpdateBuoyancy

Source code excerpt:

		}
#if ENABLE_DRAW_DEBUG
		if (CVarWaterDebugBuoyancy.GetValueOnAnyThread())
		{
			const float NumPoints = CVarWaterBuoyancyDebugPoints.GetValueOnAnyThread();
			const float Size = CVarWaterBuoyancyDebugSize.GetValueOnAnyThread();
			const float StartOffset = NumPoints * 0.5f;
			const float Scale = Size / NumPoints;
			TMap<const FSolverSafeWaterBodyData*, float> DebugSplineKeyMap;

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Public/BuoyancyTypes.h:9

Scope: file

Source code excerpt:

class AWaterBody;

extern WATER_API TAutoConsoleVariable<int32> CVarWaterDebugBuoyancy;
extern WATER_API TAutoConsoleVariable<int32> CVarWaterBuoyancyDebugPoints;
extern WATER_API TAutoConsoleVariable<int32> CVarWaterBuoyancyDebugSize;

USTRUCT(Blueprintable)
struct FSphericalPontoon
{