x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Netmulticast Client->Server & Server->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.

Product Version: UE 4.15
Tags:
more ▼

asked Jul 10 '17 at 02:44 PM in C++ Programming

avatar image

Crazy-Apple
3 4 5

avatar image HailstoneRyan Jul 10 '17 at 03:27 PM

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.

avatar image Crazy-Apple Jul 10 '17 at 03:47 PM

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;
 }

avatar image HailstoneRyan Jul 10 '17 at 07:13 PM

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

avatar image Crazy-Apple Jul 11 '17 at 12:50 AM

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.

avatar image HailstoneRyan Jul 11 '17 at 12:53 AM

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

avatar image Crazy-Apple Jul 11 '17 at 08:04 AM

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

player.rar (1.5 kB)
avatar image HailstoneRyan Jul 11 '17 at 03:06 PM

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.

avatar image Crazy-Apple Jul 11 '17 at 04:03 PM

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.

avatar image HailstoneRyan Jul 11 '17 at 04:30 PM

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.

avatar image Crazy-Apple Jul 11 '17 at 04:45 PM

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);
     }
avatar image HailstoneRyan Jul 11 '17 at 04:49 PM

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

avatar image Crazy-Apple Jul 11 '17 at 04:55 PM

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

avatar image HailstoneRyan Jul 11 '17 at 04:56 PM

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.

avatar image Crazy-Apple Jul 11 '17 at 05:02 PM

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

avatar image HailstoneRyan Jul 11 '17 at 06:10 PM

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.

avatar image Crazy-Apple Jul 11 '17 at 10:54 PM

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

avatar image KeurKeur Jul 11 '17 at 04:47 PM

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

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question