Custom Primitive Data not reading correctly in material?

I am writing custom primitive data to meshes.

I’m doing this through the OnConstruction function on a controller actor that holds an array of target meshes.

      for (TSoftObjectPtr<UMeshComponent>& MeshComponentPtr: ControlledMeshComponents)
            if (UMeshComponent* MeshComponent = MeshComponentPtr.Get())
            {
                  MeshComponent->SetDefaultCustomPrimitiveDataVector4(Index_EmissiveColor, EmissiveColor);
                  MeshComponent->SetDefaultCustomPrimitiveDataFloat(Index_EmissiveIntensity, EmissiveIntensity);
            }

The data is used in the mesh’s material (a simple unlit emissive with color/intensity inputs) to drive animated emissive intensity.

If I open the Custom Primitive Data Defaults on the mesh, the data is present and correct (emissive color / intensity)

image

But the mesh is rendering black in the viewport.

If I change the values manually in the detail panel, nothing happens.

However if I force the controller actor that is updating the CPD indices to refresh those indices by changing either color/intensity values, the mesh suddenly becomes emissive at the correct color/intensity. Data in the CPD defaults array is exactly the same.

Interestingly, OnConstruction applies those values every update whether they’ve changed or not, and changing OTHER params on the controller actor doesn’t fix the problem. It only corrects when I change one of those default CPD values, even if I change it to exactly the same value it already is on the mesh.

Once corrected, if I save and reload the level, it’s back to black again.

Hoping somebody has some advice on what I’m doing wrong here.

1 Like