UE4 C++ - How to reference and load a Blendable object for camera post-process materials
At first, I thought this would be more complicated than I thought, but it didn’t take long before I got it working. I also wanted to write a tutorial on it, in case I’ve forgotten how to do it, or if someone was stuck and wanted to search for the answer on the internet. Well, I have the answer here my friend!
To have the Post Process Materials array have a defaulted element, follow the steps below, it’s quite easy.
This is how you would load a post process material in C++ from the default constructor:
static ConstructorHelpers::FObjectFinder<UMaterialInstanceConstant> M_FPCameraScreenEffect(TEXT("MaterialInstanceConstant'/Game/PostProcess/M_CRT_Post.M_CRT_Post'"));
To get this part in the TEXT() macro: MaterialInstanceConstant'/Game/PostProcess/M_CRT_Post.M_CRT_Post' , you would need to get the object reference from the content browser, like this:
And this is how you would add the loaded object to the list of blendables/post-process materials in the default constructor:
if (M_FPCameraScreenEffect.Object) FPCamera->AddOrUpdateBlendable(M_FPCameraScreenEffect.Object, 0.02f);
And there you have it, that’s it.
Hope I have helped you!