So I am trying to get a dynamic material to render properly but when I call SetScalarParameterValue, it has no effect on the material. How can I get the material to change based on the values that are passed in?
I am a fairly inexperienced coder so prepare a grain of salt to go with my response.
I think it is unusual to set up an MID inside of the class constructor like that. I have never seen it done. I asked one of our rendering guys and he agreed; he suggested that any values there will not be initialized or will get stomped by serialization. Can you try creating the MID by some function that is triggered after postbeginplay?
After tooling around with this myself, this is the best solution I could come up with this problem.
I am new to Unreal and fairly new to C++ code, so take this advice as you wish:
RootAnnexActor.cpp
ARootAnnexActor::ARootAnnexActor()
{
...
// Add the root to hold the bounds of this Annex
AnnexBoundsMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Bounds Mesh Component"));
AnnexBoundsMeshComponent->AttachParent = RootComponent;
}
void ARootAnnexActor::OnConstruction(const FTransform &Transform)
{
Super::OnConstruction(Transform);
// Set the DynamicMaterial so we can Edit it
BoundsDynamicMaterial = AnnexBoundsMeshComponent->CreateDynamicMaterialInstance(0);
}