UStaticMeshComponent::SetMaterial() working in BeginPlay() only

I found in the below forum links the C++ code needed to change the material. However, if I move this code to any method other than BeginPlay, it does not work. So I created this method, to be called from BeginPlay, ChangeMaterial(1). It works. I call it from another method ChangeMaterial(2) that runs on a timer, I see the log, but the material does not change. I swapped the calls to be sure my dynamic materials were setup properly and whatever is called from BeginPlay is the material that shows and stays.

My goal is to change the material based on changing conditions of the pawn. In this case it is a UStaticMeshComponent that has a sphere mesh (StaticMesh’/Engine/BasicShapes/Sphere.Sphere’) assigned.

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Setup")
	class UStaticMeshComponent* SphereMesh;
	UMaterialInterface* susMat;
UMaterialInterface* hostileMat;

ConstructorHelpers::FObjectFinder<UMaterialInterface> hostileTestMat(*hostilPath);
if (hostileTestMat.Succeeded())
{
	hostileMat = hostileTestMat.Object;
}

ConstructorHelpers::FObjectFinder<UMaterialInterface> testMat (*matPath);
if (testMat.Succeeded())
{
	UE_LOG(AWGeneralLog, Error, TEXT("Got hardcoded material"));
	susMat = testMat.Object;
}

void AAWBaseNPCCharacter::ChangeMaterial(int32 flag)
{
	if (flag == 1)
	{
		UE_LOG(AWGeneralLog, Warning, TEXT("SET ..... COLOR ..... 1 "));
		UMaterialInstanceDynamic* dyn = UMaterialInstanceDynamic::Create(susMat, SphereMesh->GetStaticMesh());
		SphereMesh->SetMaterial(0, dyn);
	}
	else if (flag == 2)
	{
		UE_LOG(AWGeneralLog, Warning, TEXT("SET ..... COLOR ..... 2 "));
		UMaterialInstanceDynamic* dyn = UMaterialInstanceDynamic::Create(hostileMat, SphereMesh->GetStaticMesh());
		SphereMesh->SetMaterial(0, dyn);
	}
}

Forum link

This code works. It’s a replication issue. wanders off with a strange twitch, eye tick and a strong desire to scream into the night.