r.Water.UseSplineKeyOptimization
r.Water.UseSplineKeyOptimization
#Overview
name: r.Water.UseSplineKeyOptimization
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether to cache spline input key for water bodies.
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Water.UseSplineKeyOptimization is to control whether to cache spline input keys for water bodies in Unreal Engine’s water simulation system. This setting is part of the experimental Water plugin and is primarily used in the buoyancy component.
This setting variable is relied upon by the Water plugin, specifically within the buoyancy component of the water simulation system. The main file referencing this variable is BuoyancyComponent.cpp, which is part of the Water plugin’s runtime module.
The value of this variable is set using a TAutoConsoleVariable, which means it can be changed at runtime through console commands. By default, it is set to 1 (enabled).
The associated variable CVarWaterUseSplineKeyOptimization directly interacts with r.Water.UseSplineKeyOptimization, as they share the same value and purpose.
Developers must be aware that this variable affects the performance and accuracy of water body spline calculations. When enabled, it uses a cached method (GetWaterSplineKeyFast) to find the spline input key, which is likely faster but may be less accurate in some scenarios.
Best practices when using this variable include:
- Keep it enabled (default value of 1) for better performance in most cases.
- If precise water spline calculations are critical for your project, consider disabling it and testing the differences.
- Profile your game with this setting both enabled and disabled to determine the performance impact in your specific use case.
Regarding the associated variable CVarWaterUseSplineKeyOptimization:
- Its purpose is identical to r.Water.UseSplineKeyOptimization, serving as the actual C++ variable that controls the optimization.
- It is used directly in the BuoyancyComponent’s GetWaterSplineKey function to determine whether to use the fast (optimized) method or the standard method for finding the spline input key.
- The variable is checked using GetValueOnAnyThread(), indicating it can be accessed from multiple threads.
- In some parts of the code (BuoyancyComponentSimulation.h), the usage of this variable is commented out, suggesting that the optimization might not be applied in all cases or that the code is still experimental.
Developers should be cautious when modifying this variable and thoroughly test water-related functionality, especially buoyancy calculations, after making changes.
#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:33
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarWaterUseSplineKeyOptimization(
TEXT("r.Water.UseSplineKeyOptimization"),
1,
TEXT("Whether to cache spline input key for water bodies."),
ECVF_Default);
TAutoConsoleVariable<int32> CVarWaterBuoyancyUseAsyncPath(
TEXT("r.Water.UseBuoyancyAsyncPath"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarWaterUseSplineKeyOptimization
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/BuoyancyComponent.cpp:32
Scope: file
Source code excerpt:
ECVF_Default);
TAutoConsoleVariable<int32> CVarWaterUseSplineKeyOptimization(
TEXT("r.Water.UseSplineKeyOptimization"),
1,
TEXT("Whether to cache spline input key for water bodies."),
ECVF_Default);
TAutoConsoleVariable<int32> CVarWaterBuoyancyUseAsyncPath(
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/BuoyancyComponent.cpp:593
Scope (from outer to inner):
file
function void UBuoyancyComponent::GetWaterSplineKey
Source code excerpt:
{
float SplineInputKey;
if (CVarWaterUseSplineKeyOptimization.GetValueOnAnyThread())
{
SplineInputKey = GetWaterSplineKeyFast(Location, WaterBodyComponent, OutSegmentMap);
}
else
{
SplineInputKey = WaterBodyComponent->FindInputKeyClosestToWorldLocation(Location);
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Public/BuoyancyComponentSimulation.h:380
Scope (from outer to inner):
file
class class FBuoyancyComponentSim
function static void UpdateBuoyancy
Source code excerpt:
{
float SplineInputKey;
//if (CVarWaterUseSplineKeyOptimization.GetValueOnAnyThread())
//{
// SplineInputKey = GetWaterSplineKeyFast(Location, WaterBody, OutSegmentMap);
//}
//else
{
SplineInputKey = WaterBody->WaterSpline.FindInputKeyClosestToWorldLocation(Pontoon.CenterLocation);
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Public/BuoyancyComponentSimulation.h:452
Scope (from outer to inner):
file
class class FBuoyancyComponentSim
function static void UpdateBuoyancy
Source code excerpt:
{
float SplineInputKey;
//if (CVarWaterUseSplineKeyOptimization.GetValueOnAnyThread())
//{
// SplineInputKey = GetWaterSplineKeyFast(Location, WaterBody, OutSegmentMap);
//}
//else
{
SplineInputKey = WaterBody->WaterSpline.FindInputKeyClosestToWorldLocation(Location);