This may be a bug.
The following code fails:
UMaterialInterface* OriginalMaterial;
FString Desc;
bool bHasParameter = OriginalMaterial->GetParameterDesc(TEXT("ParamName"), Desc);
UMaterialInstanceDynamic* MaterialDynamic = UMaterialInstanceDynamic::Create(OriginalMaterial, GetTransientPackage());
check(MaterialDynamic->GetParameterDesc(TEXT("ParamDesc"), Desc);
-
Create a new blank c++ project.
-
Create a material with a scalar parameter, name it “Test”. Connect this to metallic.
-
Create a new actor c++ class. Ensure the header has the following public properties:
UPROPERTY(EditDefaultsOnly)
UMaterialInterface* Material;UPROPERTY(EditDefaultsOnly)
UMaterialInstanceDynamic* MaterialInstance; -
In BeginPlay of this class, paste the following after Super::BeginPlay():
if (Material == nullptr)
return;FString Desc;
if (Material->GetParameterDesc(TEXT(“Test”), Desc))
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::, TEXT(“Material has parameter”));MaterialInstance = UMaterialInstanceDynamic::Create(Material, this);
if(MaterialInstance->GetParameterDesc(TEXT(“Test”), Desc))
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::, TEXT(“MaterialInstance has parameter”)); -
Make a blueprint that inherits from this c++ class, and set the material to the one created in step 3.
-
Press play, not that the first message appears but the second doesn’t (but should).