Dear experts,
I have a few floor tiles and on BeginPlay() of my Character, I want random tiles to change color for a few seconds and then change back again.
For now my BeginPlay() looks like this:
So far I only pick one random tile and change the color on it by “myMesh->SetMaterial(0,tileCurrent->OnMaterial”
“OnMaterial” is a UMaterial instance and I set it on the Tile BP to a material instance I have.
void AMainCharacter::BeginPlay()
{
Super::BeginPlay();
TArray<AActor*> foundTiles;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AFloorTile::StaticClass(), foundTiles);
int32 anzahlTiles = foundTiles.Num() -1;
int32 zufall = FMath::RandRange(1,anzahlTiles);
int32 index =0;
AFloorTile* tileCurrent = nullptr;
tileCurrent = Cast<AFloorTile>(foundTiles[zufall]);
UStaticMeshComponent* myMesh = Cast<UStaticMeshComponent>(tileCurrent->GetComponentByClass(UStaticMeshComponent::StaticClass()));
myMesh->SetMaterial(0,tileCurrent->OnMaterial);
}
It works, but every time I test play the game the engine starts compiling shaders of my tiles. I know it is the shaders for the tiles because when I reduce the tiles on the floor less shaders are being compiled.
Why? Is “SetMaterial()” the wrong function to accomplish this? Or do I have to check something on the “OnMaterial” (UMaterial) ?
Thank you for any ideas!
Best regards, Peter