Hello. I’m trying to add multiplayer to my game. For begining, I want a player to change his color and all other players can see it. What I’m doing:
UPROPERTY(ReplicatedUsing = OnColorChange)
FLinearColor Color;
Here I create the property that will hold current color and will notify everyone about it’s change.
UFUNCTION()
void OnColorChange();
That should be called on property change on every client.
UFUNCTION(Reliable, Server, WithValidation, BlueprintCallable)
void ChangeColor(const FLinearColor col);
This will run on server and will be called from blueprint.
Next, *.cpp implementation:
void AMyPlayerController::ChangeColor_Implementation(const FLinearColor col)
{
Color = col;
}
bool AMyPlayerController::ChangeColor_Validate(const FLinearColor col)
{
return true;
}
void AMyPlayerController::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AMyPlayerController, Color);
}
This server function simply change color.
void AMyPlayerController::OnColorChange()
{
if (Mesh != NULL && ColorMaterial != NULL)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, Color.ToString());
ColorMaterial->SetVectorParameterValue(FName(TEXT("Color")), Color);
Mesh->SetMaterial(0, ColorMaterial);
}
}
And this should be called for every client.
The problem is when I run several clients and change color, it changes only for current player (that called this function). BUT log appears on every screen. So, every client receives notification with correct value, but visual appearance changes only for one client - who call this change. I’m totally confused and simply don’t know which direction to dig.