I have created character and teams and want to override their mesh’s material, but it seems to not work. Here’s code in shooter team game mode.
void AShooterTeamGameMode::RestartPlayer(AController* NewPlayer){
Super::RestartPlayer(NewPlayer);
UMaterialInstance* Mat;
if (Teams[0]->PlayerIsInTeam(NewPlayer)){
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, TEXT("contains player"));
if (NewPlayer->GetPawn() != NULL){
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, TEXT("has pawn"));
ACharacter* Char = Cast<ACharacter>(NewPlayer->GetPawn());
if (Char != NULL){
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, TEXT("has character"));
Mat = Cast<UMaterialInstance>(StaticLoadObject(UMaterialInstance::StaticClass(), NULL, TEXT("MaterialInstanceConstant'/Game/Temp/Character/RedInstance.RedInstance'")));
if (Mat != NULL){
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, TEXT("Material found"));
USkeletalMeshComponent* Mesh = Char->GetMesh();
if (Mesh != NULL){
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, TEXT("mesh found"));
Mesh->SetMaterial(0, Mat);
Mesh->SetMaterial(1, Mat);
Mesh->GetMaterial(0);
}
}
}
}
}
}
When i run game in editor it logs all checkpoints, from “contains player” to “mesh found”, so SetColor should run and change material, but it doesn’t. The mesh’s main and only material is at index 0.
So how do i change material from outside of actor constructor?