I’m trying to set the color of a MaterialInstanceDynamic (MID) that is created in my constructor. I want to use the color that a user sets in the details panel, however, it looks like it is not picking up this value and instead is giving it a default FLinearColor(0,0,0,1). Here is the relevant code:
.h
private:
UMaterialInterface *MasterMaterialRef; //reference to parameterized material template
UMaterialInstanceDynamic* WaterMaterialInstance; //reference to parameterized material instance that will be used to manipulate vertex locations and normal map
public:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Oasis")
TSubobjectPtr<UStaticMeshComponent> SurfaceMesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Oasis")
FLinearColor SurfaceColor;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Oasis")
float DampingFactor;
.cpp
SurfaceMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("SurfaceMesh"));
SurfaceMesh->SetSimulatePhysics(false);
PrimaryActorTick.bCanEverTick = true;
//SurfaceColor = FColor(0, 0, 255, 255); //this works, but I can't change the color through details panel!
static ConstructorHelpers::FObjectFinder<UStaticMesh> waterMesh(TEXT("StaticMesh'/Game/Shapes/Shape_Plane.Shape_Plane'"));
static ConstructorHelpers::FObjectFinder<UMaterial> waterMaterial(TEXT("Material'/Game/Materials/M_Interactive_Water.M_Interactive_Water'"));
MasterMaterialRef = waterMaterial.Object;
SurfaceMesh->SetStaticMesh(waterMesh.Object);
WaterMaterialInstance = UMaterialInstanceDynamic::Create(MasterMaterialRef, this);
WaterMaterialInstance->SetVectorParameterValue(FName(TEXT("Color")), SurfaceColor);
SurfaceMesh->SetMaterial(0, WaterMaterialInstance);
RootComponent = SurfaceMesh;
Here is my MID setup:
https://dl.dropboxusercontent.com/u/33133319/M_Interactive_Water.jpg
Here, I’ve set the color to be lime green in the details panel, but as you can see, the surface is black:
https://dl.dropboxusercontent.com/u/33133319/Oasis.jpg
What’s interesting is that the DampingFactor works, however, the DampingFactor is used at every Tick whereas the color is only used in the constructor.
Anyone have ideas about what I’m doing wrong?
TIA