[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"))
        {
        }
    };

 

posted on 2018-03-22 11:48  一粒沙  阅读(2685)  评论(0编辑  收藏  举报