Changing Dynamic Material Scaler on Client

I’m trying to make a damage flicker effect, achieved through a dynamic material, for when my enemies get hit in my multiplayer game.

This is how I’m calling the function:

void AEnemy::OnRep_Damaged() {
	PlayDamageFlash();
}

and this is how I currently have the network functions set up.

void AEnemy::PlayDamageFlash() {
	


	if (Role < ROLE_Authority) {
		//DynamicEnemyMaterial->SetScalarParameterValue(FName("StartTime"), World->GetTimeSeconds()); // <== calling it as client will cause a fatal error
		ServerPlayDamageFlash();
	}
	else {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT(" PlayDamageFlash Called on Server =: %s"), Role == ROLE_Authority ? TEXT("True") : TEXT("False")));

		DynamicEnemyMaterial->SetScalarParameterValue(FName("StartTime"), World->GetTimeSeconds());
	}
}

void AEnemy::ServerPlayDamageFlash_Implementation() {
	PlayDamageFlash();
}

bool AEnemy::ServerPlayDamageFlash_Validate() {
	return true;
}

Unfortunately, with the current set up only the server’s material flashes, but if I try to get the client’s to flash, then I’m getting an access violation on the client’s side.

I know it can work, as if I change the material scaler in the tick function, then both work.

It seems to be that the server is looking in the wrong place on the client for the location of the material using an incorrect pointer address, perhaps?

I can think of a couple of workarounds, but I’m sure this should work, and I’m just doing something stupid.
Still looking at this, but if anyone can chip in, then I would be grateful!

So, I found a solution; which was to add some null pointer guards.

For the benefit of anyone else trying to simulate a similar effect, I’ll include my approach in this answer.
Firstly, here is the part of the material which controls the flicker. This is fed into the emissive colour of the material.

Then the .h file of the Enemy class.

protected:

	UPROPERTY(ReplicatedUsing = OnRep_Damaged)
		int CurrentHealthPoints;

	UFUNCTION()
		virtual void OnRep_Damaged();

	UFUNCTION()
		void PlayDamageFlash();

and the .cpp

void AEnemy::OnRep_Damaged() {
	PlayDamageFlash();
}

void AEnemy::PlayDamageFlash() {
	if (DynamicEnemyMaterial != nullptr) {
		if (World != nullptr) {
			DynamicEnemyMaterial->SetScalarParameterValue(FName("StartTime"), World->GetTimeSeconds());
		}
		else UE_LOG(LogTemp, Warning, TEXT(" Warning: World = Null"));
	}
	else  UE_LOG(LogTemp, Warning, TEXT(" Warning: DynamicEnemyMaterial = Null"));
}