changing postprocess material instance parameters

It’s pretty straightforward to change an actor’s instance material parameters from C++ code, but it seems less straightforward for postprocess materials, because there is no material dynamic instance available, merely a plain old material instance.

I ended up doing this (in a game state’s BeginPlay()), which does work and achieves the effect I am after, but I am uncertain if it is a sanctioned technique. I feel that it might be going around the back of the API a little bit. It directly manipulates the blendable array in the post process volume, and I don’t know if that’s something one is supposed to be doing, or if it might make the sky fall down upon me in some fashion.

Has anyone set parameters in postprocess materials before? Is there a less “dirty” technique than the following?

      APostProcessVolume* volume = ...

      if (volume != nullptr) {
         auto& blendables = volume->Settings.WeightedBlendables;
         if (blendables.Array.Num() >= 1) {
            auto* mat = Cast<UMaterialInstance>(blendables.Array[0].Object);
            if (mat != nullptr)
               blendables.Array[0].Object = UMaterialInstanceDynamic::Create(mat, nullptr);

UMaterialInstanceDynamic::Create requires the second argument to be a UObject, so as long as you doing this inside one, you can use this instead of nullptr, it is working.

1 Like