How do I change material properties?

Hi there. I want to create an actor class, attach a static mesh to it with a specific color. I want to be able to drag the class to the editor and have the mesh automatically assume that color. Also, I’d like to have a property exposed that would let anyone control the material’s color without having to go to blueprints.

I tried creating a material instance for the mesh in the class constructor and that works well.
But if I try changing the color of that material in the constructor the editor crashes.
Any thoughts?

The constructors of UObject classes get run at times you might not expect – when the editor starts up, when the game first starts up, etc. Not all of the engine resources (or properties on your class) will be available or valid at that time. You might want to try setting the material property by overriding BeginPlay() on your AActor subclass. (There are also other places you can override – try PostInitializeComponents too, if you want to see it reflected in the editor interactively, I think).

Thanks for the reply cancel. I had tried to do so in both. Doing it in BeginPlay or PostInitializeComponents does indeed prevent the crash in the editor. But if I do it in BeginPlay, the material only assumes the color when I hit play. If I do it in PostInitializeComponents, it assumes the color in the editor. However, if I change the color in the code, it’s not reflected on the editor.