UGroomComponent::SetForcedLOD(-1) incorrectly calls SwitchSimulationLOD with invalid LOD index

File: Engine/Plugins/Runtime/HairStrands/Source/HairStrandsCore/Private/GroomComponent.cpp

Description

UGroomComponent::SetForcedLOD(-1) is intended to clear forced LOD and return to automatic LOD selection (Predicted/Immediate). However, it unconditionally calls SwitchSimulationLOD()

with CurrentLOD = -1, which is not a valid LOD index.

This causes two problems:

Problem 1: Unnecessary SwitchSimulationLOD call when already in auto mode

Problem 2: SwitchSimulationLOD called with -1 when transitioning from Forced to auto

Suggested Fix

After determining CurrLODSelectionType, add an early return when not setting a valid forced LOD:​

CurrLODSelectionType = bNeedSimulationNeed ? EHairLODSelectionType::Predicted : EHairLODSelectionType::Immediate;
}
 
// If not setting a valid forced LOD, just reset state and let auto system handle the rest
if (CurrLODSelectionType != EHairLODSelectionType::Forced)
{
    LODForcedIndex = CurrLODIndex;
    LODSelectionType = CurrLODSelectionType;
    return;
}
 
// Inform simulation about LOD switch.
SwitchSimulationLOD(PrevLODIndex, CurrLODIndex, CurrLODSelectionType);

Hi, thanks for calling out this logic error! I submitted the change to UE5-Main in CL 51458123. Feel free to let me know if you have any more questions.

Sounds good. I will go ahead and close out this ticket then. Have a nice weekend!

Hi, thanks for the quick turnaround! Glad the fix made it into UE5-Main. I’ll keep an eye out and reach out if anything else comes up.