Replicate property for certain player

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.

I have noticed that Log appears on every screen (regardless of who it’s called for) when playing with the ‘Use Single Instance’ option enabled in the multiplayer options, so I wouldn’t trust it in all cases.

To broadcast a message, you might look into the NetMulticast function specifier. A function with this attribute should be sent to each connected player, regardless of the owner of the actor.

As Grogger mentioned… if you are simulating your game with the “Play in Editor” setting

Use Single Process: Spawn multiple player windows in a single instance of [API:UE4] . This will load much faster, but has potential to have more issues.

checked as true, debug messages can and will show up on all clients/server regardless of the client/server that actually printed the message.

Edit:

If you see the color changing properly, you should trust that over the “PrintToScreen” debug message.

Here is a link to some good debugging code a Dev gave me in response to this same issue.