I have a post process Material as UMaterial* PPOutline1 and a DynamicMaterial as a UMaterialInstanceDynamic in my Character.h
UMaterial* PPOutline1;
UMaterialInstanceDynamic* DynamicMaterial;
What I want to is change a Vector Paramter in PPOutline to different colors based on health. I know most of the logic but I can’t seem to get Dyanmic Materials working.
In Character.cpp the constructor I do
static ConstructorHelpers::FObjectFinder<UMaterial> PPFinder(TEXT("/Game/Environment/PP_OutlineCustomDepthOcclusion"));
if (PPFinder.Succeeded()){
PPOutline1 = (UMaterial*) PPFinder.Object;
DynamicMaterial = (UMaterialInstanceDynamic*) PPOutline1;
}
And then later when it comes time to set the new color for the VectorParam of the Dynamic Material I do this
if (OtherCharacter->Health / OtherCharacter->GetMaxHealth() > 0.9f){
UE_LOG(LogTemp, Warning, TEXT("Green Health"));
if (DynamicMaterial != NULL){
DynamicMaterial->SetVectorParameterValue(FName("OutlineColor"), FLinearColor(0.0f, 1.0f, 0.0f, 1.0f));
}
}
However I always get the following crash and I know its on the line
DynamicMaterial->SetVectorParameterValue(FName("OutlineColor"), FLinearColor(0.0f, 1.0f, 0.0f, 1.0f));
http://puu.sh/iYrvr/28b360287e.png
http://puu.sh/iYrw2/76423cfd2c.png