Material expression called Compiler->Texture() without implementing UMaterialExpression::GetReferencedTexture properly

I can create material expression vector constant with following code without problem:

UMaterialExpressionVectorParameter* mepAlbedoColorTint = NewObject<UMaterialExpressionVectorParameter>(materialDefinition);
mepAlbedoColorTint->Group = *FString::Printf(TEXT("%s %d"), *FString("Layer"), (i+1));
mepAlbedoColorTint->ParameterName = *FString("Albedo Color Tint");

However TextureObjectParameter constant with similar approach gives me error:

		UMaterialExpressionTextureObjectParameter* mepRoughnessTexture = NewObject<UMaterialExpressionTextureObjectParameter>(materialDefinition);
		mepRoughnessTexture->Group = *FString::Printf(TEXT("%s %d"), *FString("Layer"), (i+1));
		mepRoughnessTexture->ParameterName = *FString("Roughness Texture");
		mepRoughnessTexture->Texture = UAssetContainer::texturePacks[i].roughness;

ERROR: Material expression called Compiler->Texture() without implementing UMaterialExpression::GetReferencedTexture properly

This is thrown from HLSLMaterialTranslator.cpp: 4935

  1. The error seems like I should make my own class of TextureObjectMaterial deriving from UMaterialExpressionTextureObjectParameter and overriding GetReferencedTexture function?
  2. If so, how can I do this “properly” like the error says?

I encountered a similar error message. The problem was I didn’t add the texture expression to the material expression list. E.g.

Material->Expressions.Add(TextureExpression)