[UE4]通过代码改变材质
OrangeMaterial = ConstructorStatics.OrangeMaterial.Get();
BlockMesh->SetMaterial(0, OrangeMaterial);
使用到的结构体如下:
struct FConstructorStatics { ConstructorHelpers::FObjectFinderOptional<UStaticMesh> PlaneMesh; ConstructorHelpers::FObjectFinderOptional<UMaterialInstance> BlueMaterial; ConstructorHelpers::FObjectFinderOptional<UMaterialInstance> OrangeMaterial; FConstructorStatics() : PlaneMesh(TEXT("/Game/Meshes/TemplateCube_Rounded.TemplateCube_Rounded")) , BlueMaterial(TEXT("/Engine/TemplateResources/MI_Template_BaseBlue.MI_Template_BaseBlue")) , OrangeMaterial(TEXT("/Engine/TemplateResources/MI_Template_BaseOrange.MI_Template_BaseOrange")) { } };