We are using CPD values of our primitives to affect when certain primitives obstruct the player to the camera so they fade out. We group them under this FadeGroupActor, which then gathers the primitives and sets the values to match. It works as expected for Static Meshes, level instances, most primitives that group under it. However, we are running into an issue when attempting to modify a primitives CPD values that is ISM or HISM, inside of a Packed Level Actor.
I’ve seen some bug reports about ISM/HISM responding strangely to CPD changes. Any advice would be much appreciated.
Attempt to modify a primitives CPD values with SetScalarParameterForDefaultCustomPrimitiveData() of an Instanced or HISM mesh, inside of a Packed Level Actor.
I started investigating this issue and found some UDN cases which seem related, some providing a workaround:
[Content removed]
[Content removed]
[Content removed]
You can try porting the solution provided in the first two cases from Blueprint to C++. If that doesn’t work, would you be able to provide a minimal repro project as that would speed up the debugging process?
Thank you for posting these links. I will try these material setups. I had ran into the first link and attempted it with no results before, I think it may be due to other factors in a complicated material. Ill setup a testing material and report back. Appreciate it.
Okay, I was able to solve. The problem was not the code I actually posted. We were collecting the data correctly. Nor was it the materials. It was how we we’re then using the data that had some incorrect checks in it. The material now fades as expected.
We have a fade component that lives on our player character. It takes the CPD values and does a bunch of other checks on the primitives before it considers them viable for fading. The code was clobbering itself at a certain point and skipping ISM/HISMs.
Relevant code for those curious:
if (Primitive->IsA(UInstancedStaticMeshComponent::StaticClass()))
{
ISMComponent = Cast<UInstancedStaticMeshComponent>(Primitive);
if (AActor* OwnerActor = ISMComponent->GetOwner())
{
if (AFadeGroupActor* FadeGroup = Cast<AFadeGroupActor>(OwnerActor->GetAttachParentActor()))
{
bIsFadeRelevant = FadeGroup->bEnableFade;
}
else
{
int32 Index = ISMComponent->GetCustomPrimitiveDataIndexForScalarParameter(CustomPrimitiveData_FadeEnabled);
const TArray<float>& CustomData = ISMComponent->GetCustomPrimitiveData().Data;
if (Index < 0 || CustomData.Num() <= Index)
{
continue;
}
bIsFadeRelevant = CustomData[Index] > 0.0f;
}
FTransform Transform;
PrimitivePosition = ISMComponent->GetComponentLocation();
ISMComponent->GetInstanceTransform(ISMIndex, Transform, true);
if (Transform.IsValid())
{
PrimitivePosition = Transform.GetLocation();
}
}
}
//// more checks here ///
///then
// Player is roughly farther away from the camera than the object, so assume it's obscuring.
if (DistCameraToPlayerSq > DistCameraToEnvObjSq)
{
// PackedLevelActor Component (UHierarchicalInstancedStaticMeshComponent) - MUST come before ISM handling
if (Primitive->IsA(UInstancedStaticMeshComponent::StaticClass()))
{
ViableEnv.Add(Primitive);
}
else if (ISMComponent)
{
if (ISMComponent->IsValidInstance(ISMIndex))
{
ViableEnvISM.Add(Elem);
}
}
else
{
ViableEnv.Add(Primitive);
}
}
Thanks for the rubber duck It prompted me to look into the rest of the code base for answers. The joys of inheriting code that you’re not familiar with.
great you found the solution to your issue and thanks for sharing the relevant code. I’m glad I could be of help. I’ll go ahead and close this case. Feel free to open a new one if you encounter more issues.