How to change material on my StaticMesh via c++ code?

I try to change material on ma staticmesh but my unreal editor crashes when I try to load myproject. I guess I do something wrong :smiley:

static ConstructorHelpers::FObjectFinder Material_Blue(TEXT(“d/Game/Materials /M_Basic_Wall_red.M_Basic_Wall_red’”));
if (Material_Blue.Succeeded())
{
SphereVisual->SetMaterial(0, Material_Blue.Object);
}

Hello Nagini,

Can you post the callstack that you receive when the editor crashes? Also, where in your code is the snippet that you posted? If it’s not in your constructor, that would cause a crash as ConstructorHelpers can only be used in the constructor.

I’d guess you’re trying to access ConstructorHelper in a non-constructor function? In that case, you can use StaticLoadObject to find your material instead.

U are right, I did use ConstructorHelpers in non-contructor function. Thanks guys for help, I will try to solve this :slight_smile: