How can I set a scalar parameter on a material for a static mesh?

I’ve looked at other questions pertaining to this topic, but they all seem to revolve around FObjectFinder in the constructor. Both my dynamic material and static mesh are being set in blueprints. I need to get that material off of my static mesh component with C++. This is how it’s done in blueprints:

I just need to know what is the C++ equivalent of the above? I’ve tried:

C->FindComponentByClass(UStaticMeshComponent::StaticClass())->

However, I can’t reach the material from there unless I’m missing something. I could really use some help.

#Answer

 if(!TheStaticMeshActor || !TheStaticMeshActor->StaticMeshComponent)
    {
     return;
    }

    UMaterialInstanceDynamic* Mat_Inst = TheStaticMeshActor->StaticMeshComponent->GetMaterial(0);
    if(Mat_Inst)
    {
      Mat_Inst->SetScalarParameterValue(FName("ParameterName"), 333.014); //new value
    }

#MaterialInstanceDynamic.h

for more info

#:heart:

Rama

Thanks, but how can I actually see the StaticMeshActor and Component? I have a reference to my actor, but I’m not sure how to get the component. I’ve tried FindComponentByClass and GetComponentByClass like this:

C->FindComponentByClass(UStaticMeshComponent::StaticClass()) but I can’t seem to get the actual component.

C is my actor.