The Static Mesh Component is part of an Actor but you are Casting Directly to UStaticMeshComponent, The Owner Can’t be a StaticMesh in this Case but an Actor.
It should Cast To AActor then from that Actor you need to access its StaticMesh and Change its Material.
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Mesh")
class UStaticMeshComponent* StaticMesh;
//This is a quick function for getting mesh in case you put variables in private (I would suggest FORCEINLINE but that can get a bit different for new people but still take a look at those
UFUNCTION()
class UStaticMeshComponent* GetStaticMeshFromActor();
MyActor.cpp
#include "Materials/MaterialInterface.h"
#include "Components/StaticMeshComponent.h"
AMyActor::AMyActor()
{
//Constructor
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
SetRootComponent(StaticMesh);
}
//The Getter Function in case you made the Variable private/protected
UStaticMeshComponent* AApplyMaterialQuestion::GetStaticMeshFromActor()
{
return StaticMesh;
}
Now The Component
ChangeMaterialComponent.h
UPROPERTY(EditDefaultsOnly, Category = "Material")
class UMaterialInterface* NewMat;