Update Clients variable

Hmm actually you increment index on client, after that you change on server.
In this form replication is useless, i dont know why you want server validated int for media playing, but i have some idea.

So first, if you are sure you want change that int on server, do not change on client.
If NextMedia called check you have authority or not, if not only just call ServerNextMedia (and onrep actually dont need to be called)

After this server will replicate the new value and will run your onrep function.

Second: i do not see player is marked replicated? Maybe in default characterd are marked, but do SetIsReplicated(true) for sure.

Third: if you try to achieve some kind of syncronized media playing, where more player can switch between media and all players need to be see that selected media, well thrn you doing wrong.
Because int will be replicated to every player, but code will not run because in multiplayer local player have rights, other players are only simulated actors… so if one of that simulated actor int will be replicated, he CANT change local actors (player) media!!! (Recommendation: read Cedric’s network compedium :wink: http://cedric-neukirchen.net/Downloads/Compendium/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf)

So if you try to achieve this kind of achieve this kind of mechanism, you need to work with NetMultiCast RPC
Which can be started from server and will run in every client…

In short: player change media → server rpc to change media → server sends netmulticast rpc to all clients to play switch new media

Hello ,

I try to update a int variable in the player class, Im using a Dedicated Server.
When a client increment the variable and replicate to the server, the server update the variable for all clients.

But dont work , I dont know when I have to update the variable to the clients and how exactly.

Some help please ?

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Character.h"
#include "PlayerCharacter.generated.h"

UCLASS()
class BASEPROJECT_API APlayerCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	APlayerCharacter();
	virtual void Tick(float DeltaTime) override;
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	UFUNCTION()
		void PlayMedia();
	UFUNCTION()
		void NextMedia();

	UFUNCTION(Reliable, Server, WithValidation)
		void ServerPlayMedia();
	virtual void ServerPlayMedia_Implementation();
	virtual bool ServerPlayMedia_Validate();

	UFUNCTION()
		virtual void OnRep_PlayMedia();

	UFUNCTION(Reliable, Server, WithValidation)
		void ServerNextMedia();
	virtual void ServerNextMedia_Implementation();
	virtual bool ServerNextMedia_Validate();

	UFUNCTION()
		virtual void OnRep_NextMedia();

	void ChangeIndex(int idx);

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:

	UPROPERTY(EditAnywhere, Replicated)
		UMediaPlayer* MediaPlayer;

	UPROPERTY(EditAnywhere, Replicated)
		TArray<FString> RepPathList;

	UPROPERTY(EditAnywhere, ReplicatedUsing=OnRep_PlayMedia)
		int		RepIndex;

};

// Fill out your copyright notice in the Description page of Project Settings.

#include "BaseProject.h"
#include "UnrealNetwork.h"
#include "PlayerCharacter.h"


// Sets default values
APlayerCharacter::APlayerCharacter()
{
	static ConstructorHelpers::FObjectFinder<UMediaPlayer> mediaP(TEXT("/Game/Movies/MediaPlayer"));
	if (mediaP.Succeeded())
		MediaPlayer = mediaP.Object;
}

// Called when the game starts or when spawned
void APlayerCharacter::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void APlayerCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("RepIndex Tick : %d"), RepIndex));

}

// Called to bind functionality to input
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);


	InputComponent->BindAction("PlayMedia", IE_Pressed, this, &APlayerCharacter::PlayMedia);
	InputComponent->BindAction("NextMedia", IE_Pressed, this, &APlayerCharacter::NextMedia);
}

void APlayerCharacter::PlayMedia()
{
	RepIndex = 0;

	ChangeIndex(RepIndex); 

	if (Role < ROLE_Authority)
	{
		ServerPlayMedia();
		OnRep_PlayMedia();
	}
}

void APlayerCharacter::OnRep_PlayMedia()
{
	ChangeIndex(RepIndex);
}

void APlayerCharacter::ServerPlayMedia_Implementation()
{
	PlayMedia();
}

bool APlayerCharacter::ServerPlayMedia_Validate()
{
	return true;
}

void APlayerCharacter::NextMedia()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Purple, TEXT("On Client"));

	RepIndex++;
	ChangeIndex(RepIndex);

	if (Role < ROLE_Authority)
	{
		ServerNextMedia();
		OnRep_NextMedia();
	}
}

void APlayerCharacter::OnRep_NextMedia()
{
	ChangeIndex(RepIndex);
}

void APlayerCharacter::ServerNextMedia_Implementation()
{
	NextMedia();
}

bool APlayerCharacter::ServerNextMedia_Validate()
{
	return true;
}

void APlayerCharacter::ChangeIndex(int idx)
{
	RepIndex = idx;
	if (RepIndex >= RepPathList.Num())
		RepIndex = 0;
	if (RepPathList.IsValidIndex(RepIndex))
	{
		if (MediaPlayer->OpenFile(RepPathList[RepIndex]))
		{
			MediaPlayer->Play();
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FString::Printf(TEXT(" RepIndex : %d"), RepIndex));
		}
	}
}


void APlayerCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(APlayerCharacter, MediaPlayer);
	DOREPLIFETIME(APlayerCharacter, RepIndex);
}

Thanks you for the help