Netmulticast Client->Server & Server->Clients

You don’t need NetMulticast to update variable values. You only need to set that variable as Replicated. The server handles updating the clients for you.

Replication doesn’t happen instantly. Print the value of RepIndex in Tick.

I try do this : Player change Index → Server rpc to change Index → Server sends netmulticast rpc to all Clients to switch new Index.

But my problem is to use NetMulticast , dont understand it Doc NetMulticast , thats what I need , but dont know how manipulate it

thats the code :

Player Class

There’s no need to use NetMulticast in this scenario. You’ve setup the variable to replicate which means when it changes on the authority the new value will be replicated to the non-authoritative connections automatically. Have you tested this? Under what conditions? How many clients connected?

Just as a note you may want to rename this class. Naming it AplayerCharacter is bound to cause some confusion at some point.

Changes to the variable on the authority (server or hosting client) will be replicated to the non-authority players (connected clients) automatically, yes. Changes made locally on the non-authority players will be overwritten with any changes made on the authority.

Hello,

I am really interesset by the subject, I plan to play with server with unreal. Therefore, I would like to know the answer (or to have an example) in order to anticipate this problem. I started to read some tutorials but it’s not really explicit for me.

best regards,
Keurkeur

Does the player you’re pressing the key on have authority (are they the host?)

If you’re connecting to a dedicated server the player won’t ever be the authority, no.

Which means the Server functions you were using before need to be used and you shouldn’t check for authority when pressing the key.

On the key press, no you don’t need an authority check because when you press the key you want to send an RPC to the server letting it know you want to increase the value of that variable. Once that value changes on the server (the authority) it will be replicated (because of the UPROPERTY specifiers) to the connected clients.

Deer community , hello

Im a beginner , im trying to do a Dedicated server.
I do some research about the possibility of a client to update a variable and send it to others clients.
I have to pass the replicate variable to the server , then the server update the variable and send it to clients. For that I read the NetMulticast is a good option.

My question is , how I use it, I try to understand , but dont know how used it. I read for a replication I need 4 function (Server, Implementation , validate , NetMulticast , Implementation, validate) ?
I tryed , but not work.

If its possible could you help me , with a example please , im a bit lost.

Thanks.

In my class player I have a variable type int (Replicated)

I just try to change increase it with input, I just want after the replication , have the same value on others clients.

you said the server handles updating clients, but when the server update the value of clients by the variable change of random client ?

Thats my code, if you could explain me, because he dont work.
If I increase the index with the client 1 , the client 2 dont have the same value in Index.
The Actor is replicated in the contructor.

	UFUNCTION()
		void IncreaseIndex();

	UFUNCTION(Reliable, Server, WithValidation)
		void ServerIncreaseIndex();
	virtual void ServerIncreaseIndex_Implementation();
	virtual bool ServerIncreaseIndex_Validate();

UPROPERTY(EditAnywhere, Replicated)
		int		RepIndex;

void APCharacter::IncreaseIndex()
{
	RepIndex++;

	if (Role < ROLE_Authority)
		ServerIncreaseIndex();
}

void APCharacter::ServerIncreaseIndex_Implementation()
{
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString("Role : ") + FString::FromInt(Role) + FString(" : ") + GetName());

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


}

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

I tryed , but well not work , in fact dont know who a replicate can be update by server for all clients. Without OnRep or Netmulticast. But thank you for you time.

I’m not sure what you’re not understanding. Show the full CPP and H file of your class if you want more help.

Sorry I clearly dont understand. I tryed this tuto link text.
But you are saying I have to change the variable when he is on the Authority and it will apply on the non-authority ?
So did I have to use (Implementation , validate ) ?
To be sure to understand correctly for example , clients have a boolean, and client 1 die so boolean death pass to false , so all clients die using just a replicate without function server ?
I connect 2 or 3 clients for the moment.

thanks for you answer, I tryed as I understand and did this , but in thicks , the variable dont change :

	UFUNCTION()
		void IncreaseIndex();

	UPROPERTY(EditAnywhere, Replicated)
		int		RepIndex;

 void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
    {
    	Super::SetupPlayerInputComponent(PlayerInputComponent);
    
    	InputComponent->BindAction("NextMedia", IE_Pressed, this, &APlayerCharacter::IncreaseIndex);
    }

void APlayerCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	GEngine->AddOnScreenDebugMessage(-1, 0.5f, FColor::White, FString::FromInt(Role) + FString(" : ") + GetName() + FString::Printf(TEXT("/ RepIndex : %d"), RepIndex));

}
    void APlayerCharacter::IncreaseIndex()
    {
    	if (HasAuthority())
    		RepIndex++;
    }
    
    void APlayerCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
    {	
            DOREPLIFETIME(APlayerCharacter, RepIndex);
    }

the variable dont change when the key is pressed so , he dont have the authority I suppose.
I did like this for the dedicated server link text , so I dont think they can be host

Thats why I tryed with UFUNCTION(Server, WithValidation), but dont know if its the good process.

So I dont need it to check authority , but how it will be replicated , because if I change the variable in the client , others doesn’t change

Ok Im at the same point ^^. Anyway thanks for you comments